package com.corona.game;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.util.SpriteProxy;
import com.corona.game.util.TextureCache;
import com.sun.jna.platform.win32.COM.tlb.imp.TlbBase;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.Reader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import org.lwjgl.system.macosx.CoreGraphics;
import oshi.util.Constants;

/* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon.class */
public class Pokemon extends OverworldThing {
    public static ArrayList<String> attacksImplemented = new ArrayList<>();
    public static List<String> onlySwim;
    public static ArrayList<String> aggroAnyway;
    public static ArrayList<String> dontAggro;
    private Boolean _isSkittish;
    public static ArrayList<String> skittishMons;
    public static HashMap<String, Texture> textures;
    public static HashMap<String, String> baseSpecies;
    public static HashMap<String, ArrayList<String>> eggMoves;
    private static final Vector2[] POSITIONS;
    private Vector2 startPos;
    private Vector2 endPos;
    private Vector2 currPos;
    public static HashMap<String, Float> weights;
    public String nickname;
    public Specie specie;
    public int level;
    public int exp;
    public String dexNumber;
    public int happiness;
    public boolean isShiny;
    public String growthRateGroup;
    public Map<String, Integer> baseStats;
    public Map<String, Integer> currentStats;
    public Map<String, Integer> statStages;
    public Map<String, Integer> maxStats;
    public ArrayList<String> hms;
    public String status;
    public int statusCounter;
    public ArrayList<String> volatileStatus;
    public HashMap<String, Integer> volatileStatusCounter;
    public int disabledIndex;
    public int disabledCounter;
    public boolean flinched;
    public SpriteProxy sprite;
    public SpriteProxy backSprite;
    public Map<String, Sprite> standingSprites;
    public Map<String, Sprite> movingSprites;
    public Map<String, Sprite> altMovingSprites;
    public Action standingAction;
    public DrawUpper drawUpper;
    public DrawLower drawLower;
    public Sprite currOwSprite;
    public int spriteOffsetY;
    public boolean canMove;
    public Map<Vector2, Tile> mapTiles;
    public int interiorIndex;
    public boolean isRunning;
    public boolean shouldMove;
    public Player.Type type;
    public Player previousOwner;
    public boolean inHabitat;
    public boolean inShelter;
    private List<String[]> habitats;
    public String hasItem;
    public int harvestTimer;
    public int harvestTimerMax;
    public ArrayList<String> harvestables;
    public ArrayList<Sprite> avatarSprites;
    public SpriteProxy breathingSprite;
    public ArrayList<String> types;
    public int angry;
    public int eating;
    public String[] attacks;
    public String gender;
    public String[] eggGroups;
    public boolean isEgg;
    public boolean isGhost;
    public Pokemon loveInterest;
    public static int layEggTimerMax;
    public int layEggTimer;
    public int nearbyEggs;
    public String trappedBy;
    public int trapCounter;
    public Pokemon cantEscapeBy;
    public Map<Integer, String[]> learnSet;
    public boolean inBattle;
    public boolean aggroPlayer;
    public boolean interactedWith;
    public boolean drawThisFrame;
    public boolean isTrapping;
    public Tile onTile;
    public boolean inWater;
    public boolean isCharmed;
    public boolean participatedInBattle;
    public boolean gainedLevel;
    public Generation generation;
    public ArrayList<SpriteProxy> introAnim;
    public ArrayList<String> moveDirs;
    public ArrayList<Integer> ledgeJumps;
    public ArrayList<Float> numMoves;
    public static Random rand;
    public Map<String, Sprite> surfSprites;
    public Map<String, Sprite> surfMovingSprites;
    public Pokemon friend;
    public static int friendTimerMax;
    public int friendTimer;
    public String _baseSpecie;
    public static int currStagger;
    public static int maxStagger;
    private static final Vector2[] FRIEND_OFFSETS;

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Generation.class */
    public enum Generation {
        RED,
        CRYSTAL
    }

    static {
        BufferedReader br = new BufferedReader(Gdx.files.internal("pokemon/attacks_implemented.txt").reader());
        while (true) {
            try {
                String line = br.readLine();
                if (line == null) {
                    break;
                }
                attacksImplemented.add(line);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        onlySwim = new ArrayList();
        onlySwim.add("magikarp");
        onlySwim.add("gyarados");
        onlySwim.add("remoraid");
        onlySwim.add("chinchou");
        onlySwim.add("lanturn");
        onlySwim.add("goldeen");
        onlySwim.add("seaking");
        onlySwim.add("horsea");
        onlySwim.add("seadra");
        onlySwim.add("kingdra");
        onlySwim.add("feebas");
        onlySwim.add("lapras");
        onlySwim.add("carvanha");
        onlySwim.add("sharpedo");
        aggroAnyway = new ArrayList<>();
        aggroAnyway.add("poochyena");
        aggroAnyway.add("sneasel");
        aggroAnyway.add("skarmory");
        aggroAnyway.add("pinsir");
        aggroAnyway.add("tauros");
        aggroAnyway.add("duraludon");
        dontAggro = new ArrayList<>();
        dontAggro.add("bellossom");
        dontAggro.add("gardevoir");
        dontAggro.add("jumpluff");
        dontAggro.add("marill");
        dontAggro.add("chansey");
        dontAggro.add("blissey");
        dontAggro.add("pikachu");
        skittishMons = new ArrayList<>();
        skittishMons.add("ekans");
        skittishMons.add("pidgey");
        skittishMons.add("spearow");
        skittishMons.add("rattata");
        skittishMons.add("chansey");
        textures = new HashMap<>();
        baseSpecies = new HashMap<>();
        eggMoves = new HashMap<>();
        try {
            String[] strArr = {"credited/", ""};
            for (String path : strArr) {
                Reader reader = Gdx.files.internal("pokemon/" + path + "evos_attacks.asm").reader();
                BufferedReader br2 = new BufferedReader(reader);
                String currMon = null;
                while (true) {
                    String line2 = br2.readLine();
                    if (line2 == null) {
                        break;
                    } else if (line2.contains("EvosAttacks:")) {
                        currMon = line2.split("EvosAttacks:")[0].toLowerCase(Locale.ROOT);
                    } else if (currMon != null && !line2.contains(";")) {
                        if (line2.contains("EVOLVE")) {
                            String[] vals = line2.split(", ");
                            String baseMon = baseSpecies.get(currMon);
                            if (baseMon == null) {
                                baseMon = currMon;
                            }
                            baseSpecies.put(vals[2].toLowerCase(Locale.ROOT), baseMon);
                        } else if (!line2.contains(TlbBase.TAB)) {
                            if (baseSpecies.get(currMon) == null) {
                                baseSpecies.put(currMon, currMon);
                            }
                            currMon = null;
                        }
                    }
                }
                reader.close();
                baseSpecies.put("darmanitanzen", "darumaka");
                baseSpecies.put("aexeggutor", "exeggcute");
                baseSpecies.put("araichu", "pichu");
                baseSpecies.put("mantine", "mantyke");
                baseSpecies.put("combee_female", "combee");
                if (Game.fairyTypeEnabled) {
                    baseSpecies.put("azurill", "azurill");
                    baseSpecies.put("marill", "azurill");
                    baseSpecies.put("azumarill", "azurill");
                }
                baseSpecies.put("amarowak", "cubone");
                Reader reader2 = Gdx.files.internal("pokemon/" + path + "egg_moves.asm").reader();
                BufferedReader br3 = new BufferedReader(reader2);
                String currMon2 = null;
                while (true) {
                    String line3 = br3.readLine();
                    if (line3 != null) {
                        if (line3.contains("EggMoves:")) {
                            currMon2 = line3.split("EggMoves:")[0].toLowerCase(Locale.ROOT);
                            eggMoves.put(currMon2, new ArrayList<>());
                        } else if (currMon2 != null && !line3.contains(";")) {
                            if (!line3.contains(TlbBase.TAB)) {
                                currMon2 = null;
                            } else {
                                eggMoves.get(currMon2).add(line3.split("db ")[1].trim().toLowerCase(Locale.ROOT).replace("_", " "));
                            }
                        }
                    }
                }
            }
        } catch (FileNotFoundException e2) {
            e2.printStackTrace();
        } catch (IOException e3) {
            e3.printStackTrace();
        }
        POSITIONS = new Vector2[]{new Vector2(-16.0f, -16.0f), new Vector2(0.0f, -16.0f), new Vector2(16.0f, -16.0f), new Vector2(-16.0f, 0.0f), new Vector2(0.0f, 0.0f), new Vector2(16.0f, 0.0f), new Vector2(-16.0f, 16.0f), new Vector2(0.0f, 16.0f), new Vector2(16.0f, 16.0f)};
        weights = new HashMap<>();
        try {
            Reader reader3 = Gdx.files.internal("pokemon/pokemon_weights_kg.txt").reader();
            BufferedReader br4 = new BufferedReader(reader3);
            while (true) {
                String line4 = br4.readLine();
                if (line4 == null) {
                    break;
                }
                String[] attrs = line4.split(TlbBase.TAB);
                String key = String.format(Locale.ROOT, "%03d", Integer.valueOf(attrs[0]));
                if (!weights.containsKey(key)) {
                    weights.put(key, Float.valueOf(attrs[1]));
                }
            }
            reader3.close();
        } catch (IOException e4) {
            e4.printStackTrace();
        }
        layEggTimerMax = 7200;
        rand = new Random();
        friendTimerMax = 960;
        currStagger = 0;
        maxStagger = 96;
        FRIEND_OFFSETS = new Vector2[]{new Vector2(-16.0f, 0.0f), new Vector2(16.0f, 0.0f), new Vector2(0.0f, -16.0f), new Vector2(0.0f, 16.0f)};
    }

    public boolean isSkittish() {
        if (this._isSkittish == null) {
            this._isSkittish = Boolean.valueOf(skittishMons.contains(this.specie.name));
        }
        return this._isSkittish.booleanValue();
    }

    public static String nameToIndex(String name) {
        String name2 = name.toLowerCase(Locale.ROOT);
        if (name2.contains("unown")) {
            name2 = "unown";
        }
        if (name2.equals("farfetch_d")) {
            name2 = "farfetch�d";
        }
        if (name2.equals("ho_oh")) {
            name2 = "ho-oh";
        }
        if (name2.equals("aexeggutor")) {
            name2 = "exeggutor";
        } else if (name2.equals("araichu")) {
            name2 = "raichu";
        } else if (name2.equals("gcorsola")) {
            name2 = "corsola";
        } else if (name2.equals("gyamask")) {
            name2 = "yamask";
        } else if (name2.equals("gdarumaka")) {
            name2 = "darumaka";
        } else if (name2.equals("gdarmanitan")) {
            name2 = "darmanitan";
        } else if (name2.equals("gdarmanitanzen")) {
            name2 = "darmanitan";
        } else if (name2.equals("darmanitanzen")) {
            name2 = "darmanitan";
        } else if (name2.equals("combee_female")) {
            name2 = "combee";
        } else if (name2.equals("amarowak")) {
            name2 = "marowak";
        }
        int lineNum = 1;
        try {
            BufferedReader br = new BufferedReader(Gdx.files.internal("pokemon/pokemon_to_index.txt").reader());
            while (true) {
                String line = br.readLine();
                if (line == null || line.equalsIgnoreCase(name2)) {
                    break;
                }
                lineNum++;
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e2) {
            e2.printStackTrace();
        }
        if (name2.equals("straigar")) {
            lineNum = 2;
        }
        return String.format(Locale.ROOT, "%03d", Integer.valueOf(lineNum));
    }

    public Pokemon(Network.PokemonDataBase pokemonData) {
        this._isSkittish = null;
        this.startPos = new Vector2();
        this.endPos = new Vector2();
        this.currPos = new Vector2();
        this.happiness = 1;
        this.isShiny = false;
        this.growthRateGroup = "";
        this.baseStats = new HashMap();
        this.currentStats = new HashMap();
        this.statStages = new HashMap();
        this.statStages.put("attack", 0);
        this.statStages.put("defense", 0);
        this.statStages.put("specialAtk", 0);
        this.statStages.put("specialDef", 0);
        this.statStages.put("speed", 0);
        this.statStages.put("accuracy", 0);
        this.statStages.put("evasion", 0);
        this.maxStats = new HashMap();
        this.hms = new ArrayList<>();
        this.status = null;
        this.statusCounter = 0;
        this.volatileStatus = new ArrayList<>();
        this.volatileStatusCounter = new HashMap<>();
        this.disabledIndex = -1;
        this.disabledCounter = 0;
        this.flinched = false;
        this.standingSprites = new HashMap();
        this.movingSprites = new HashMap();
        this.altMovingSprites = new HashMap();
        this.standingAction = null;
        this.drawUpper = null;
        this.drawLower = null;
        this.currOwSprite = null;
        this.spriteOffsetY = 0;
        this.canMove = true;
        this.interiorIndex = 100;
        this.isRunning = false;
        this.shouldMove = false;
        this.type = Player.Type.LOCAL;
        this.previousOwner = null;
        this.inHabitat = false;
        this.inShelter = false;
        this.habitats = new ArrayList();
        this.habitats.add(new String[]{"green"});
        this.hasItem = null;
        this.harvestTimer = 0;
        this.harvestTimerMax = 9000;
        this.harvestables = new ArrayList<>();
        this.harvestables.add("manure");
        this.avatarSprites = new ArrayList<>();
        this.breathingSprite = null;
        this.gender = null;
        this.eggGroups = new String[2];
        this.isEgg = false;
        this.isGhost = false;
        this.loveInterest = null;
        this.layEggTimer = layEggTimerMax;
        this.nearbyEggs = 0;
        this.trappedBy = null;
        this.trapCounter = 0;
        this.cantEscapeBy = null;
        this.inBattle = false;
        this.aggroPlayer = false;
        this.interactedWith = false;
        this.drawThisFrame = true;
        this.isTrapping = false;
        this.inWater = false;
        this.isCharmed = false;
        this.participatedInBattle = false;
        this.gainedLevel = false;
        this.moveDirs = new ArrayList<>();
        this.ledgeJumps = new ArrayList<>();
        this.numMoves = new ArrayList<>();
        this.surfSprites = null;
        this.surfMovingSprites = null;
        this.friend = null;
        this.friendTimer = friendTimerMax;
        this._baseSpecie = null;
        if (pokemonData instanceof Network.PokemonDataV05) {
            this.isEgg = ((Network.PokemonDataV05) pokemonData).name.equals("egg");
            if (((Network.PokemonDataV05) pokemonData).eggHatchInto != null) {
                pokemonData.name = ((Network.PokemonDataV05) pokemonData).eggHatchInto;
            }
        }
        init(pokemonData.name, pokemonData.level, pokemonData.generation, pokemonData.isShiny, this.isEgg);
        this.currentStats.put("hp", Integer.valueOf(pokemonData.hp));
        this.attacks[0] = pokemonData.attacks[0];
        this.attacks[1] = pokemonData.attacks[1];
        this.attacks[2] = pokemonData.attacks[2];
        this.attacks[3] = pokemonData.attacks[3];
        this.position = pokemonData.position;
        if (pokemonData instanceof Network.PokemonDataV07) {
            this.interiorIndex = ((Network.PokemonDataV07) pokemonData).interiorIndex;
        }
        if (pokemonData.isInterior) {
            System.out.println("this.nickname");
            System.out.println(this.nickname);
            System.out.println("Game.staticGame.map.interiorTilesIndex");
            System.out.println(Game.staticGame.map.interiorTilesIndex);
            System.out.println("this.interiorIndex");
            System.out.println(this.interiorIndex);
            this.mapTiles = Game.staticGame.map.interiorTiles.get(this.interiorIndex);
        } else {
            this.mapTiles = Game.staticGame.map.overworldTiles;
        }
        initHabitatValues();
        this.status = pokemonData.status;
        this.harvestTimer = pokemonData.harvestTimer;
        if (pokemonData.previousOwnerName != null) {
            this.previousOwner = Game.staticGame.player;
            if (Game.staticGame.players.containsKey(pokemonData.previousOwnerName)) {
                this.previousOwner = Game.staticGame.players.get(pokemonData.previousOwnerName);
            }
        }
        if (pokemonData instanceof Network.PokemonDataV05) {
            this.gender = ((Network.PokemonDataV05) pokemonData).gender;
            this.happiness = ((Network.PokemonDataV05) pokemonData).friendliness;
            this.aggroPlayer = ((Network.PokemonDataV05) pokemonData).aggroPlayer;
        }
        if (pokemonData instanceof Network.PokemonDataV07) {
            this.nickname = ((Network.PokemonDataV07) pokemonData).nickname;
        }
        if (pokemonData instanceof Network.PokemonData) {
            this.exp = ((Network.PokemonData) pokemonData).exp;
        }
    }

    public Pokemon(String name, int level) {
        this(name, level, Generation.CRYSTAL);
    }

    public Pokemon(String name, int level, Generation generation) {
        this(name, level, generation, rand.nextInt(Game.staticGame.shinyRate) == 0);
    }

    public Pokemon(String name, int level, Generation generation, boolean isShiny) {
        this(name, level, generation, isShiny, false);
    }

    public Pokemon(String name, int level, Generation generation, boolean isShiny, boolean isEgg) {
        this._isSkittish = null;
        this.startPos = new Vector2();
        this.endPos = new Vector2();
        this.currPos = new Vector2();
        this.happiness = 1;
        this.isShiny = false;
        this.growthRateGroup = "";
        this.baseStats = new HashMap();
        this.currentStats = new HashMap();
        this.statStages = new HashMap();
        this.statStages.put("attack", 0);
        this.statStages.put("defense", 0);
        this.statStages.put("specialAtk", 0);
        this.statStages.put("specialDef", 0);
        this.statStages.put("speed", 0);
        this.statStages.put("accuracy", 0);
        this.statStages.put("evasion", 0);
        this.maxStats = new HashMap();
        this.hms = new ArrayList<>();
        this.status = null;
        this.statusCounter = 0;
        this.volatileStatus = new ArrayList<>();
        this.volatileStatusCounter = new HashMap<>();
        this.disabledIndex = -1;
        this.disabledCounter = 0;
        this.flinched = false;
        this.standingSprites = new HashMap();
        this.movingSprites = new HashMap();
        this.altMovingSprites = new HashMap();
        this.standingAction = null;
        this.drawUpper = null;
        this.drawLower = null;
        this.currOwSprite = null;
        this.spriteOffsetY = 0;
        this.canMove = true;
        this.interiorIndex = 100;
        this.isRunning = false;
        this.shouldMove = false;
        this.type = Player.Type.LOCAL;
        this.previousOwner = null;
        this.inHabitat = false;
        this.inShelter = false;
        this.habitats = new ArrayList();
        this.habitats.add(new String[]{"green"});
        this.hasItem = null;
        this.harvestTimer = 0;
        this.harvestTimerMax = 9000;
        this.harvestables = new ArrayList<>();
        this.harvestables.add("manure");
        this.avatarSprites = new ArrayList<>();
        this.breathingSprite = null;
        this.gender = null;
        this.eggGroups = new String[2];
        this.isEgg = false;
        this.isGhost = false;
        this.loveInterest = null;
        this.layEggTimer = layEggTimerMax;
        this.nearbyEggs = 0;
        this.trappedBy = null;
        this.trapCounter = 0;
        this.cantEscapeBy = null;
        this.inBattle = false;
        this.aggroPlayer = false;
        this.interactedWith = false;
        this.drawThisFrame = true;
        this.isTrapping = false;
        this.inWater = false;
        this.isCharmed = false;
        this.participatedInBattle = false;
        this.gainedLevel = false;
        this.moveDirs = new ArrayList<>();
        this.ledgeJumps = new ArrayList<>();
        this.numMoves = new ArrayList<>();
        this.surfSprites = null;
        this.surfMovingSprites = null;
        this.friend = null;
        this.friendTimer = friendTimerMax;
        this._baseSpecie = null;
        init(name, level, generation, isShiny, isEgg);
        if (this.specie.name.equals("combee") && this.gender.equals("female")) {
            updateSpecieInfo("combee_female");
        }
    }

    public void updateSpecieInfo(String specieName) {
        updateSpecieInfo(specieName, null);
    }

    public void updateSpecieInfo(final String specieName, String prevSpecieNickname) {
        if (!Specie.species.containsKey(specieName)) {
            if (Thread.currentThread() != Game.staticGame.gameThread) {
                Runnable runnable = new Runnable() { // from class: com.corona.game.Pokemon.1
                    @Override // java.lang.Runnable
                    public void run() {
                        try {
                            Specie.species.put(specieName, new Specie(specieName));
                        } catch (Exception e) {
                            e.printStackTrace();
                        }
                        synchronized (this) {
                            notify();
                        }
                    }
                };
                Gdx.app.postRunnable(runnable);
                try {
                    synchronized (runnable) {
                        runnable.wait();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            } else {
                Specie.species.put(specieName, new Specie(specieName));
            }
        }
        this.specie = Specie.species.get(specieName);
        if (this.specie == null) {
            System.out.println("No such specie exists: " + specieName);
        }
        if (prevSpecieNickname == null || prevSpecieNickname.equalsIgnoreCase(this.nickname)) {
            this.nickname = getNickname();
        }
        if (this.isEgg) {
            this.nickname = "egg";
            this.sprite = Specie.spriteEgg;
            this.backSprite = Specie.backSpriteEgg;
            this.introAnim = Specie.introAnimEgg;
        } else if (this.isShiny) {
            this.sprite = this.specie.spriteShiny;
            this.backSprite = this.specie.backSpriteShiny;
            this.introAnim = this.specie.introAnimShiny;
        } else {
            this.sprite = this.specie.sprite;
            this.backSprite = this.specie.backSprite;
            this.introAnim = this.specie.introAnim;
        }
        this.learnSet = this.specie.learnSet;
        this.dexNumber = this.specie.dexNumber;
        this.baseStats = this.specie.baseStats;
        this.types = this.specie.types;
        this.growthRateGroup = this.specie.growthRateGroup;
        this.eggGroups = this.specie.eggGroups;
        if (!this.isEgg) {
            this.hms = this.specie.hms;
        }
        loadOverworldSprites();
        calcMaxStats();
        initHabitatValues();
    }

    public void init(String specieName, int level, Generation generation, boolean isShiny, boolean isEgg) {
        if (level <= 0) {
            System.out.println("Bad level: " + String.valueOf(level));
            level = 1;
        }
        this.generation = generation;
        this.level = level;
        this.isEgg = isEgg;
        this.isShiny = isShiny;
        updateSpecieInfo(specieName);
        this.currentStats = new HashMap(this.maxStats);
        this.angry = 0;
        this.eating = 0;
        this.attacks = new String[]{null, null, null, null};
        if (this.specie.genderRatio.equals("GENDER_UNKNOWN")) {
            this.gender = Constants.UNKNOWN;
        } else {
            int percentFemale = 0;
            if (this.specie.genderRatio.equals("GENDER_F12_5")) {
                percentFemale = 125;
            } else if (this.specie.genderRatio.equals("GENDER_F25")) {
                percentFemale = 250;
            } else if (this.specie.genderRatio.equals("GENDER_F50")) {
                percentFemale = 500;
            } else if (this.specie.genderRatio.equals("GENDER_F75")) {
                percentFemale = 750;
            } else if (this.specie.genderRatio.equals("GENDER_F100")) {
                percentFemale = 1000;
            }
            if (rand.nextInt(CoreGraphics.kCGErrorFailure) < percentFemale) {
                this.gender = "female";
            } else {
                this.gender = "male";
            }
        }
        this.happiness = this.specie.baseHappiness;
        if (this.isEgg) {
            this.happiness = this.specie.eggCycles;
        }
        getCurrentAttacks();
        this.exp = calcExpForLevel(this.level);
    }

    public String baseSpecie() {
        if (this._baseSpecie == null) {
            String name = this.specie.name;
            if (name.contains("unown")) {
                name = "unown";
            }
            this._baseSpecie = baseSpecies.get(name);
        }
        return this._baseSpecie;
    }

    public boolean hasEvo() {
        return !Specie.gen2Evos.get(this.specie.name).isEmpty();
    }

    public void calcMaxStats() {
        this.maxStats.put("hp", Integer.valueOf((((this.baseStats.get("hp").intValue() + 50) * this.level) / 50) + 10));
        this.maxStats.put("attack", Integer.valueOf(((this.baseStats.get("attack").intValue() * this.level) / 50) + 10));
        this.maxStats.put("defense", Integer.valueOf(((this.baseStats.get("defense").intValue() * this.level) / 50) + 10));
        this.maxStats.put("specialAtk", Integer.valueOf(((this.baseStats.get("specialAtk").intValue() * this.level) / 50) + 10));
        this.maxStats.put("specialDef", Integer.valueOf(((this.baseStats.get("specialDef").intValue() * this.level) / 50) + 10));
        this.maxStats.put("speed", Integer.valueOf(((this.baseStats.get("speed").intValue() * this.level) / 50) + 10));
        this.maxStats.put("catchRate", this.baseStats.get("catchRate"));
    }

    /* JADX WARNING: Code restructure failed: missing block: B:70:0x0326, code lost:
        r17 = false;
     */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    void checkHabitat(Game r8) {
        /*
        // Method dump skipped, instructions count: 1163
        */
        throw new UnsupportedOperationException("Method not decompiled: com.corona.game.Pokemon.checkHabitat(com.corona.Game):void");
    }

    public void gainLevel(int numLevels) {
        int prevMaxHp = this.maxStats.get("hp").intValue();
        this.level += numLevels;
        calcMaxStats();
        for (String stat : this.maxStats.keySet()) {
            if (stat.equals("hp")) {
                this.currentStats.put(stat, Integer.valueOf(this.currentStats.get("hp").intValue() + (this.maxStats.get("hp").intValue() - prevMaxHp)));
            } else {
                this.currentStats.put(stat, this.maxStats.get(stat));
            }
        }
        if (this.happiness < 100) {
            gainHappiness(5);
        } else if (this.happiness < 200) {
            gainHappiness(3);
        } else {
            gainHappiness(2);
        }
    }

    public void gainHappiness(int amount) {
        this.happiness += amount;
        if (this.happiness > 220) {
            this.happiness = 220;
        } else if (this.happiness < 0) {
            this.happiness = 0;
        }
    }

    public String getNickname() {
        String nickname = this.specie.name;
        if (this.specie.modNickname != null) {
            nickname = this.specie.modNickname;
        } else if (nickname.equals("aexeggutor")) {
            nickname = "exeggutor";
        } else if (nickname.equals("araichu")) {
            nickname = "raichu";
        } else if (nickname.equals("gcorsola")) {
            nickname = "corsola";
        } else if (nickname.equals("gyamask")) {
            nickname = "yamask";
        } else if (nickname.equals("gdarumaka")) {
            nickname = "darumaka";
        } else if (nickname.equals("gdarmanitan")) {
            nickname = "darmanitan";
        } else if (nickname.equals("gdarmanitanzen")) {
            nickname = "darmanitan";
        } else if (nickname.equals("darmanitanzen")) {
            nickname = "darmanitan";
        } else if (nickname.equals("combee_female")) {
            nickname = "combee";
        } else if (nickname.equals("mrmime")) {
            nickname = "mr.mime";
        } else if (nickname.contains("unown")) {
            nickname = "unown";
        } else if (nickname.equals("farfetch_d")) {
            nickname = "farfetch�d";
        } else if (nickname.equals("nidoran_f") || nickname.equals("nidoran_m")) {
            nickname = "nidoran";
        } else if (nickname.equals("straigar")) {
            nickname = "raitora";
        } else if (nickname.equals("amarowak")) {
            nickname = "marowak";
        }
        return nickname;
    }

    public void hatch() {
        this.isEgg = false;
        loadOverworldSprites();
        this.nickname = getNickname();
        this.hms = this.specie.hms;
        if (this.isShiny) {
            this.sprite = this.specie.spriteShiny;
            this.backSprite = this.specie.backSpriteShiny;
            this.introAnim = this.specie.introAnimShiny;
        } else {
            this.sprite = this.specie.sprite;
            this.backSprite = this.specie.backSprite;
            this.introAnim = this.specie.introAnim;
        }
        this.happiness = 100;
    }

    public void spookify() {
        this.isGhost = true;
        this.nickname = "ghost";
        this.sprite = Specie.spriteGhost;
        this.backSprite = null;
        this.introAnim = Specie.introAnimGhost;
    }

    public Pokemon revealGhost() {
        if (this.types.contains("GHOST")) {
            this.isGhost = false;
        }
        loadOverworldSprites();
        this.nickname = this.specie.name;
        float x = this.sprite.getX();
        float y = this.sprite.getY();
        if (this.isShiny) {
            this.sprite = this.specie.spriteShiny;
            this.backSprite = this.specie.backSpriteShiny;
            this.introAnim = this.specie.introAnimShiny;
        } else {
            this.sprite = this.specie.sprite;
            this.backSprite = this.specie.backSprite;
            this.introAnim = this.specie.introAnim;
        }
        this.sprite.setPosition(x, y);
        return this;
    }

    public void removeDrawActions(Game game) {
        game.actionStack.remove(this.standingAction);
        game.actionStack.remove(this.drawUpper);
        game.actionStack.remove(this.drawLower);
        game.map.onscreenPokemon.remove(this);
        this.drawUpper = null;
        this.drawLower = null;
    }

    public void evolveTo(String targetName) {
        int prevMaxHp = this.maxStats.get("hp").intValue();
        int prevCurrentHp = this.currentStats.get("hp").intValue();
        updateSpecieInfo(targetName, getNickname());
        this.currentStats.put("hp", Integer.valueOf(prevCurrentHp + (this.maxStats.get("hp").intValue() - prevMaxHp)));
        this.status = null;
    }

    void initHabitatValues() {
        this.harvestables = this.specie.harvestables;
        this.habitats = parseHabitats(this.specie.habitats);
        this.harvestTimerMax = this.specie.harvestTimerMax;
    }

    private List<String[]> parseHabitats(List<String> originals) {
        List<String[]> habitats = new ArrayList<>();
        for (int i = 0; i < originals.size(); i++) {
            habitats.add(originals.get(i).split("\\|"));
        }
        return habitats;
    }

    public boolean gen2ApplyStatStage(String stat, int stage) {
        if (!stat.equals("all")) {
            return gen2ApplyStatStage(stat, stage, false);
        }
        boolean succeeded = false;
        for (String statName : new String[]{"attack", "defense", "specialAtk", "specialDef", "speed"}) {
            succeeded = succeeded || gen2ApplyStatStage(statName, stage, false);
        }
        return succeeded;
    }

    boolean gen2ApplyStatStage(String stat, int stage, boolean override) {
        int newStage = this.statStages.get(stat).intValue() + stage;
        if (!override && (newStage < -6 || newStage > 6)) {
            return false;
        }
        this.statStages.put(stat, Integer.valueOf(newStage));
        if (stat.equals("accuracy") || stat.equals("evasion")) {
            return true;
        }
        float multiplier = ((float) Math.max(2, 2 + newStage)) / ((float) Math.max(2, 2 - newStage));
        int currStat = this.maxStats.get(stat).intValue();
        if (this.status != null) {
            if (stat.equals("speed") && this.status.equals("paralyze")) {
                currStat /= 4;
            } else if (stat.equals("attack") && this.status.equals("burn")) {
                currStat /= 4;
            }
        }
        int newStat = (int) (multiplier * ((float) currStat));
        if (newStat < 1) {
            newStat = 1;
        }
        if (newStat > 999) {
            newStat = 999;
        }
        this.currentStats.put(stat, Integer.valueOf(newStat));
        return true;
    }

    public int calcExpForLevel(int level) {
        if (this.growthRateGroup.contains("FAST")) {
            return (4 * ((level * level) * level)) / 5;
        }
        if (this.growthRateGroup.contains("MEDIUM_FAST")) {
            return level * level * level;
        }
        if (this.growthRateGroup.contains("MEDIUM_SLOW")) {
            return ((((6 * ((level * level) * level)) / 5) - (15 * (level * level))) + (100 * level)) - 140;
        }
        if (this.growthRateGroup.contains("SLOW")) {
            return (5 * ((level * level) * level)) / 4;
        }
        if (this.growthRateGroup.contains("FLUCTUATING")) {
            if (level < 15) {
                return (int) (((double) (level * level * level)) * ((Math.floor((double) ((((float) level) + 1.0f) / 3.0f)) + 24.0d) / 50.0d));
            }
            if (level < 36) {
                return (int) (((float) (level * level * level)) * ((((float) level) + 14.0f) / 50.0f));
            }
            return (int) (((double) (level * level * level)) * ((Math.floor((double) (((float) level) / 2.0f)) + 32.0d) / 50.0d));
        } else if (!this.growthRateGroup.contains("ERRATIC")) {
            System.out.println("Error: invalid growth group for " + this.specie.name + ", group: " + String.valueOf(this.growthRateGroup));
            return level * level * level;
        } else if (level < 50) {
            return (int) ((((float) ((level * level) * level)) * (100.0f - ((float) level))) / 50.0f);
        } else {
            if (level < 68) {
                return (int) ((((float) ((level * level) * level)) * (150.0f - ((float) level))) / 100.0f);
            }
            if (level < 98) {
                return (int) ((((double) ((level * level) * level)) * Math.floor((double) ((1911.0f - (10.0f * ((float) level))) / 3.0f))) / 500.0d);
            }
            return (int) ((((float) ((level * level) * level)) * (160.0f - ((float) level))) / 100.0f);
        }
    }

    public void getCurrentAttacks() {
        int i = 0;
        for (Integer level : this.learnSet.keySet()) {
            String[] strArr = this.learnSet.get(level);
            for (String attack : strArr) {
                if (level.intValue() <= this.level) {
                    boolean foundMove = false;
                    int j = 0;
                    while (true) {
                        if (j >= this.attacks.length) {
                            break;
                        } else if (this.attacks[j] != null && this.attacks[j].equalsIgnoreCase(attack)) {
                            foundMove = true;
                            break;
                        } else {
                            j++;
                        }
                    }
                    if (!foundMove) {
                        this.attacks[i] = attack;
                        i++;
                        if (i >= this.attacks.length) {
                            i = 0;
                        }
                    }
                }
            }
        }
    }

    void loadOverworldSprites() {
        if (this.isEgg) {
            this.movingSprites = this.specie.movingSpritesEgg;
            this.altMovingSprites = this.specie.altMovingSpritesEgg;
            this.standingSprites = this.specie.standingSpritesEgg;
            this.avatarSprites = this.specie.avatarSpritesEgg;
            return;
        }
        this.spriteOffsetY = this.specie.spriteOffsetY;
        this.movingSprites = this.specie.movingSprites;
        this.altMovingSprites = this.specie.altMovingSprites;
        this.standingSprites = this.specie.standingSprites;
        this.avatarSprites = this.specie.avatarSprites;
        this.surfSprites = this.specie.surfSprites;
        this.surfMovingSprites = this.specie.surfMovingSprites;
    }

    public void resetStatStages() {
        this.statStages.put("attack", 0);
        this.statStages.put("defense", 0);
        this.statStages.put("specialAtk", 0);
        this.statStages.put("specialDef", 0);
        this.statStages.put("speed", 0);
        this.statStages.put("accuracy", 0);
        this.statStages.put("evasion", 0);
        for (String stat : this.maxStats.keySet()) {
            if (!stat.equals("hp")) {
                this.currentStats.put(stat, this.maxStats.get(stat));
            }
        }
        if (this.status == null) {
            return;
        }
        if (this.status.equals("paralyze")) {
            this.currentStats.put("speed", Integer.valueOf(this.currentStats.get("speed").intValue() / 4));
        } else if (this.status.equals("burn")) {
            this.currentStats.put("attack", Integer.valueOf(this.currentStats.get("attack").intValue() / 4));
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$AddToInventory.class */
    public class AddToInventory extends Action {
        public Action.Layer layer = Action.Layer.map_130;
        Vector2 position;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public AddToInventory(Vector2 position, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.position = position;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            Action newAction;
            if (Pokemon.this.type == Player.Type.REMOTE) {
                game.client.sendTCP(new Network.DropPokemon(game.player.network.id, Pokemon.this.position));
            }
            if (game.player.pokemon.size() < 6) {
                game.player.pokemon.add(Pokemon.this);
                game.map.pokemon.remove(this.position);
                Pokemon.this.removeDrawActions(game);
                if (!Pokemon.this.isEgg || Pokemon.this.previousOwner == game.player) {
                    newAction = new PlayMusic("seed1", (Action) null);
                } else {
                    newAction = new DisplayText(game, game.player.name + " received an EGG.", "Berry_Get.ogg", (Action) null, (Action) null);
                    boolean playedSound = false;
                    Vector2 startPos = Pokemon.this.position.cpy().add(-160.0f, -160.0f);
                    startPos.x = (float) (((int) startPos.x) - (((int) startPos.x) % 16));
                    startPos.y = (float) (((int) startPos.y) - (((int) startPos.y) % 16));
                    Vector2 endPos = Pokemon.this.position.cpy().add(160.0f, 160.0f);
                    endPos.x = (float) (((int) endPos.x) - (((int) endPos.x) % 16));
                    endPos.y = (float) (((int) endPos.y) - (((int) endPos.y) % 16));
                    int offSet = 0;
                    Vector2 currPos = new Vector2(startPos.x, startPos.y);
                    while (currPos.y < endPos.y) {
                        Pokemon pokemon = game.map.pokemon.get(currPos);
                        currPos.x += 16.0f;
                        if (currPos.x > endPos.x) {
                            currPos.x = startPos.x;
                            currPos.y += 16.0f;
                        }
                        if (!(pokemon == null || pokemon.isEgg || pokemon.previousOwner == game.player)) {
                            boolean sameBaseSpecie = pokemon.baseSpecie().equals(Pokemon.this.baseSpecie());
                            boolean shareEggGroup = false;
                            String[] strArr = pokemon.eggGroups;
                            for (String group1 : strArr) {
                                String[] strArr2 = Pokemon.this.eggGroups;
                                int length = strArr2.length;
                                int i = 0;
                                while (true) {
                                    if (i >= length) {
                                        break;
                                    } else if (group1.equals(strArr2[i])) {
                                        shareEggGroup = true;
                                        break;
                                    } else {
                                        i++;
                                    }
                                }
                            }
                            if (sameBaseSpecie || shareEggGroup) {
                                if (!playedSound) {
                                    game.insertAction(new PlayMusic("ledge2", (Action) null));
                                    playedSound = true;
                                }
                                Objects.requireNonNull(pokemon);
                                game.insertAction(new SetField(pokemon, "canMove", false, new Emote("!", new SetField(pokemon, "canMove", true, new SetField(pokemon, "aggroPlayer", true, null)))));
                                if (pokemon.standingAction != null && (pokemon.standingAction instanceof Standing)) {
                                    ((Standing) pokemon.standingAction).aggroTimer = -2 * offSet;
                                }
                                offSet++;
                            }
                        }
                    }
                }
                if (game.player.pokemon.size() >= 6 && !game.player.displayedMaxPartyText) {
                    game.player.displayedMaxPartyText = true;
                    newAction.append(new DisplayText(game, "Your party is full! You will need to DROP some of them in order to catch more.", (String) null, false, true, (Action) null));
                }
                Pokemon.this.previousOwner = game.player;
                Pokemon.this.isRunning = false;
                if (Pokemon.this.loveInterest != null) {
                    Pokemon.this.loveInterest.loveInterest = null;
                    Pokemon.this.loveInterest = null;
                }
                if (Pokemon.this.friend != null) {
                    Pokemon.this.friend.friend = null;
                    Pokemon.this.friend = null;
                }
                newAction.append(this.nextAction);
                game.actionStack.remove(this);
                game.insertAction(newAction);
                return;
            }
            game.actionStack.remove(this);
            game.insertAction(new DisplayText.Clear(game, new WaitFrames(game, 3, new PlayMusic("error1", new DisplayText(game, "Not enough room in your party!", (String) null, (Action) null, new WaitFrames(game, 6, this.nextAction))))));
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$DrawLower.class */
    public class DrawLower extends Action {
        public Action.Layer layer;
        Sprite spritePart;
        public boolean isEgg;
        public boolean following;
        int timer;

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public DrawLower() {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.layer = Action.Layer.map_130;
            this.spritePart = new Sprite();
            this.isEgg = false;
            this.following = false;
            Pokemon.currStagger = Math.floorMod(Pokemon.currStagger + 1, Pokemon.maxStagger);
            this.timer = Pokemon.currStagger;
            this$0.drawLower = this;
            Game game = Game.staticGame;
            if (game.map != null && !game.map.onscreenPokemon.contains(this$0)) {
                game.map.refreshOnscreenPokemon = true;
            }
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public DrawLower(boolean following) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.layer = Action.Layer.map_130;
            this.spritePart = new Sprite();
            this.isEgg = false;
            this.following = false;
            Pokemon.currStagger = Math.floorMod(Pokemon.currStagger + 1, Pokemon.maxStagger);
            this.timer = Pokemon.currStagger;
            this$0.drawLower = this;
            this.following = following;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            this.isEgg = Pokemon.this.isEgg;
            game.map.upkeepTimers.pokemonBuckets[this.timer].add(Pokemon.this);
            game.actionStack.remove(this);
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (Pokemon.this.hasItem == null && !this.isEgg) {
                if (Pokemon.this.inHabitat) {
                    Pokemon.this.harvestTimer += Pokemon.maxStagger;
                    if (Pokemon.this.inShelter) {
                        Pokemon.this.harvestTimer += Pokemon.maxStagger;
                    }
                }
                if (Pokemon.this.harvestTimer >= Pokemon.this.harvestTimerMax) {
                    Pokemon.this.hasItem = Pokemon.this.harvestables.get(game.map.rand.nextInt(Pokemon.this.harvestables.size()));
                }
            }
            if (Pokemon.this.loveInterest != null && Pokemon.this.inHabitat && Pokemon.this.nearbyEggs < 3 && ((Pokemon.this.gender.equals("female") || (Pokemon.this.eggGroups[0].equals("EGG_DITTO") && Pokemon.this.loveInterest.gender.equals("male"))) && Pokemon.this.layEggTimer > 0)) {
                Pokemon.this.layEggTimer -= Pokemon.maxStagger;
            }
            if (Pokemon.this.friend != null && Pokemon.this.friendTimer > 0) {
                Pokemon.this.friendTimer -= Pokemon.maxStagger;
            }
        }

        public void draw(Game game) {
            if ((Pokemon.this.drawThisFrame || this.following) && game.map.tiles == Pokemon.this.mapTiles && !Pokemon.this.inWater) {
                this.spritePart.set(Pokemon.this.currOwSprite);
                this.spritePart.setRegionY(Pokemon.this.currOwSprite.getRegionY() + (Pokemon.this.currOwSprite.getRegionHeight() - 8));
                this.spritePart.setRegionHeight(8);
                game.mapBatch.draw(this.spritePart, Pokemon.this.position.x, Pokemon.this.position.y + 4.0f);
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$DrawUpper.class */
    public class DrawUpper extends Action {
        public Action.Layer layer;
        Sprite spritePart;
        public boolean following;
        public int floatTimer;
        public int floatOffset;
        public int floatOffset2;

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public DrawUpper() {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.layer = Action.Layer.map_116;
            this.spritePart = new Sprite();
            this.following = false;
            this.floatTimer = 0;
            this.floatOffset = 0;
            this.floatOffset2 = 0;
            this$0.drawUpper = this;
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public DrawUpper(boolean following) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.layer = Action.Layer.map_116;
            this.spritePart = new Sprite();
            this.following = false;
            this.floatTimer = 0;
            this.floatOffset = 0;
            this.floatOffset2 = 0;
            this.following = following;
            this$0.drawUpper = this;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            if (Pokemon.this.specie.name.equals("lapras")) {
                this.floatOffset2 = 5;
            } else if (Pokemon.this.specie.name.equals("anorith")) {
                this.floatOffset2 = 2;
            } else if (Pokemon.this.specie.name.equals("araichu")) {
                this.floatOffset2 = 7;
            } else if (Pokemon.this.specie.name.equals("mantine")) {
                this.floatOffset2 = 4;
            } else if (Pokemon.this.specie.name.equals("sharpedo")) {
                this.floatOffset2 = 2;
            }
            game.actionStack.remove(this);
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            draw(game);
        }

        public void draw(Game game) {
            if ((Pokemon.this.drawThisFrame || this.following) && game.map.tiles == Pokemon.this.mapTiles) {
                this.spritePart.set(Pokemon.this.currOwSprite);
                this.spritePart.setRegionY(Pokemon.this.currOwSprite.getRegionY());
                if (Pokemon.this.inWater) {
                    this.spritePart.setRegionHeight((Pokemon.this.currOwSprite.getRegionHeight() - 8) + this.floatOffset + this.floatOffset2);
                    this.floatTimer++;
                    if (this.floatTimer > 80) {
                        this.floatTimer = 0;
                    }
                    if (this.floatTimer % 80 == 0) {
                        this.floatOffset = 0;
                    } else if (this.floatTimer % 80 == 40) {
                        this.floatOffset = 1;
                    }
                    game.mapBatch.draw(this.spritePart, Pokemon.this.position.x, Pokemon.this.position.y + 8.0f);
                    return;
                }
                this.spritePart.setRegionHeight(Pokemon.this.currOwSprite.getRegionHeight() - 8);
                game.mapBatch.draw(this.spritePart, Pokemon.this.position.x, Pokemon.this.position.y + 12.0f);
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Emote.class */
    public class Emote extends Action {
        String type;
        Sprite sprite;
        public Action.Layer layer = Action.Layer.map_109;
        HashMap<String, Sprite> sprites = new HashMap<>();
        int timer = 0;

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Emote(String type, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.type = type;
            Texture text = TextureCache.get(Gdx.files.internal("emotes.png"));
            int i = 0;
            for (String name : new String[]{"!", "?", "happy", "skull", "heart", "bolt", "sleep", "fish", "uncomfortable", "..."}) {
                this.sprites.put(name, new Sprite(text, 16 * i, 0, 16, 16));
                i++;
            }
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            this.sprite = this.sprites.get(this.type);
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (game.map.tiles == Pokemon.this.mapTiles) {
                game.mapBatch.draw(this.sprite, Pokemon.this.position.x, Pokemon.this.position.y + 4.0f + 16.0f);
            }
            if (this.timer >= 60) {
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            }
            this.timer++;
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Sliding.class */
    public class Sliding extends Action {
        Vector2 startPos;
        Vector2 targetPos;
        Tile startTile;
        Tile targetTile;
        String dirFacing;
        public Action.Layer layer = Action.Layer.map_113;
        int timer = 0;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Sliding(String dirFacing, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.dirFacing = dirFacing;
            this.nextAction = nextAction;
            this.startPos = new Vector2(this$0.position);
            this.targetPos = this$0.facingPos(new Vector2(), this.dirFacing);
            if (!(this$0.standingAction instanceof Follow)) {
                if (Game.staticGame.map.pokemon.containsKey(this$0.position) && Game.staticGame.map.pokemon.get(this$0.position) == this$0) {
                    Game.staticGame.map.pokemon.remove(this$0.position);
                }
                Game.staticGame.map.pokemon.put(this.targetPos.cpy(), this$0);
            }
            this$0.canMove = true;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            this.startTile = game.map.tiles.get(this.startPos);
            this.targetTile = game.map.tiles.get(this.targetPos);
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (Pokemon.this.canMove && game.playerCanMove) {
                if (this.dirFacing.equals("up")) {
                    Pokemon.this.position.y += 2.0f;
                } else if (this.dirFacing.equals("down")) {
                    Pokemon.this.position.y -= 2.0f;
                } else if (this.dirFacing.equals("left")) {
                    Pokemon.this.position.x -= 2.0f;
                } else if (this.dirFacing.equals("right")) {
                    Pokemon.this.position.x += 2.0f;
                }
                if (this.timer > 6) {
                    game.actionStack.remove(this);
                    game.insertAction(this.nextAction);
                    Pokemon.this.position.set(this.targetPos);
                    Pokemon.this.standingAction = this.nextAction;
                    if (Pokemon.this.standingAction instanceof Follow) {
                        Pokemon.this.checkHabitat(game);
                    } else if (game.player.currFieldMove.equals("")) {
                        Pokemon.this.checkHabitat(game);
                    }
                    this.nextAction.step(game);
                }
                this.timer++;
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Moving.class */
    public class Moving extends Action {
        public Action.Layer layer;
        Vector2 initialPos;
        Vector2 targetPos;
        float xDist;
        float yDist;
        boolean alternate;
        int delay;
        int timer;
        float numMove;
        String dirFacing;
        boolean isFollowing;
        int timer2;
        Sprite standingSprite;

        public Moving(Pokemon this$0, int delay, float numMove, boolean alternate, Action nextAction) {
            this(this$0.dirFacing, delay, numMove, alternate, false, nextAction);
        }

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Moving(String dirFacing, int delay, float numMove, boolean alternate, boolean isFollowing, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.layer = Action.Layer.map_130;
            this.delay = 1;
            this.timer = 1;
            this.numMove = 1.0f;
            this.isFollowing = false;
            this.timer2 = 0;
            this.dirFacing = dirFacing;
            this.delay = delay;
            this.numMove = numMove;
            this.alternate = alternate;
            this.isFollowing = isFollowing;
            this.nextAction = nextAction;
            this.initialPos = new Vector2(this$0.position);
            if (this.dirFacing.equals("up")) {
                this.targetPos = new Vector2(this$0.position.x, this$0.position.y + 16.0f);
            } else if (this.dirFacing.equals("down")) {
                this.targetPos = new Vector2(this$0.position.x, this$0.position.y - 16.0f);
            } else if (this.dirFacing.equals("left")) {
                this.targetPos = new Vector2(this$0.position.x - 16.0f, this$0.position.y);
            } else if (this.dirFacing.equals("right")) {
                this.targetPos = new Vector2(this$0.position.x + 16.0f, this$0.position.y);
            }
            if (!this.isFollowing) {
                if (Game.staticGame.map.pokemon.containsKey(this$0.position) && Game.staticGame.map.pokemon.get(this$0.position) == this$0) {
                    Game.staticGame.map.pokemon.remove(this$0.position);
                }
                Game.staticGame.map.pokemon.put(this.targetPos.cpy(), this$0);
            }
            this$0.canMove = true;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            if (!this.isFollowing && game.battle.drawAction == null && game.playerCanMove && game.map.tiles == Pokemon.this.mapTiles && Pokemon.this.position.dst2(game.player.position) < 16384.0f && this.numMove > 1.0f) {
                if (this.numMove <= 1.5f) {
                    if (Pokemon.this.inWater) {
                        game.insertAction(new PlayMusic("swim1_dupe", 0.5f, true, null));
                        game.insertAction(new PlayMusic("sand1_dupe", 0.4f, true, null));
                        Pokemon pokemon = Pokemon.this;
                        Objects.requireNonNull(pokemon);
                        game.insertAction(new SurfWakeAnim(null));
                        Pokemon pokemon2 = Pokemon.this;
                        Objects.requireNonNull(pokemon2);
                        game.insertAction(new WaterSplash(true, new Vector2(0.0f, 0.0f), null));
                    } else {
                        game.insertAction(new PlayMusic("ride1", 1.0f, true, null));
                    }
                } else if (this.numMove <= 8.0f && Pokemon.this.inWater) {
                    game.insertAction(new PlayMusic("puddle3", 0.6f, true, null));
                    game.insertAction(new PlayMusic("menu_open1", 0.9f, true, null));
                    Pokemon pokemon3 = Pokemon.this;
                    Objects.requireNonNull(pokemon3);
                    game.insertAction(new SurfWakeAnim(null));
                    Pokemon pokemon4 = Pokemon.this;
                    Objects.requireNonNull(pokemon4);
                    game.insertAction(new WaterSplash(true, new Vector2(0.0f, 0.0f), null));
                }
            }
            if (Pokemon.this.layEggTimer <= 0 && Pokemon.this.loveInterest != null && !game.map.pokemon.containsKey(this.initialPos)) {
                Pokemon.this.layEggTimer = Pokemon.layEggTimerMax;
                String baseSpecies = Pokemon.baseSpecies.get(Pokemon.this.specie.name.toLowerCase(Locale.ROOT));
                if (Pokemon.this.specie.name.equals("ditto")) {
                    baseSpecies = Pokemon.baseSpecies.get(Pokemon.this.loveInterest.specie.name.toLowerCase(Locale.ROOT));
                }
                if (baseSpecies.equals("nidoran_f") && Game.rand.nextInt(256) < 128) {
                    baseSpecies = "nidoran_m";
                }
                Pokemon pokemonEgg = new Pokemon(baseSpecies, 5, Generation.CRYSTAL, Game.rand.nextInt(256) == 0, true);
                int currIndex = 0;
                int i = 0;
                while (true) {
                    if (i >= pokemonEgg.attacks.length) {
                        break;
                    } else if (pokemonEgg.attacks[i] == null) {
                        currIndex = i;
                        break;
                    } else {
                        i++;
                    }
                }
                if (Pokemon.eggMoves.get(baseSpecies) != null) {
                    Iterator<String> it = Pokemon.eggMoves.get(baseSpecies).iterator();
                    while (it.hasNext()) {
                        String move = it.next();
                        String[] strArr = Pokemon.this.loveInterest.attacks;
                        for (String attack : strArr) {
                            if (move.equals(attack)) {
                                boolean foundMove = false;
                                int j = 0;
                                while (true) {
                                    if (j >= pokemonEgg.attacks.length) {
                                        break;
                                    } else if (Pokemon.this.attacks[j] != null && Pokemon.this.attacks[j].equalsIgnoreCase(attack)) {
                                        foundMove = true;
                                        break;
                                    } else {
                                        j++;
                                    }
                                }
                                if (!foundMove) {
                                    pokemonEgg.attacks[currIndex] = move;
                                    currIndex = (currIndex + 1) % 4;
                                }
                            }
                        }
                    }
                }
                pokemonEgg.mapTiles = Pokemon.this.mapTiles;
                pokemonEgg.position = this.initialPos.cpy();
                game.map.pokemon.put(pokemonEgg.position.cpy(), pokemonEgg);
                Objects.requireNonNull(pokemonEgg);
                game.insertAction(new Standing());
            }
            if (game.type == Game.Type.SERVER) {
                for (Player player : game.players.values()) {
                    if (player.network.loadingZone.contains(this.targetPos)) {
                        game.server.sendToTCP(player.network.connectionId, new Network.MovePokemon(Pokemon.this));
                    } else if (player.network.loadingZone.contains(Pokemon.this.position)) {
                        game.server.sendToTCP(player.network.connectionId, new Network.OverworldPokemonData(Pokemon.this, Pokemon.this.position, true));
                    }
                }
            }
            this.standingSprite = new Sprite(Pokemon.this.standingSprites.get(this.dirFacing));
            if (this.alternate && Pokemon.this.specie.name.equals("dratini") && (Pokemon.this.dirFacing.equals("up") || Pokemon.this.dirFacing.equals("down"))) {
                this.standingSprite.flip(true, false);
            } else if (this.alternate && Pokemon.this.specie.name.equals("dragonair")) {
                if (Pokemon.this.dirFacing.equals("up") || Pokemon.this.dirFacing.equals("down")) {
                    this.standingSprite.flip(true, false);
                }
            }
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (Pokemon.this.canMove) {
                this.timer--;
                if (this.timer <= 0) {
                    this.timer = this.delay;
                    if (this.dirFacing.equals("up")) {
                        Pokemon.this.position.y += this.numMove;
                    } else if (this.dirFacing.equals("down")) {
                        Pokemon.this.position.y -= this.numMove;
                    } else if (this.dirFacing.equals("left")) {
                        Pokemon.this.position.x -= this.numMove;
                    } else if (this.dirFacing.equals("right")) {
                        Pokemon.this.position.x += this.numMove;
                    }
                }
                this.xDist = Math.abs(this.initialPos.x - Pokemon.this.position.x);
                this.yDist = Math.abs(this.initialPos.y - Pokemon.this.position.y);
                if ((this.yDist >= 13.0f || this.yDist <= 2.0f) && (this.xDist >= 13.0f || this.xDist <= 2.0f)) {
                    Pokemon.this.currOwSprite = this.standingSprite;
                } else if (this.alternate) {
                    Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(this.dirFacing);
                } else {
                    Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(this.dirFacing);
                }
                if (((int) this.xDist) == 8 || ((int) this.yDist) == 8 || ((int) this.xDist) == 9 || ((int) this.yDist) == 9) {
                    Tile currTile = Pokemon.this.mapTiles.get(this.targetPos);
                    Pokemon.this.inWater = false;
                    if (currTile != null && currTile.name.contains("water") && !currTile.name.contains("_tidal")) {
                        Pokemon.this.inWater = true;
                    }
                }
                if (this.xDist >= 16.0f || this.yDist >= 16.0f) {
                    Pokemon.this.position.set(this.targetPos);
                    game.actionStack.remove(this);
                    game.insertAction(this.nextAction);
                    Pokemon.this.standingAction = this.nextAction;
                    if (this.isFollowing) {
                        if (game.player.currFieldMove.equals("")) {
                            Pokemon.this.checkHabitat(game);
                        }
                        this.nextAction.step(game);
                        return;
                    }
                    Pokemon.this.checkHabitat(game);
                }
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$RemoveFromInventory.class */
    public class RemoveFromInventory extends Action {
        public Action.Layer layer = Action.Layer.map_130;
        int moveTimer = 0;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public RemoveFromInventory() {
            super(new Object[0]);
            Pokemon.this = this$0;
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            if (game.type == Game.Type.CLIENT) {
                Pokemon.this.type = Player.Type.REMOTE;
                game.client.sendTCP(new Network.DropPokemon(game.player.network.id, DrawPokemonMenu.currIndex, game.player.dirFacing));
            }
            game.player.pokemon.remove(Pokemon.this);
            game.map.pokemon.put(Pokemon.this.position.cpy(), Pokemon.this);
            Pokemon.this.moveDirs.clear();
            Pokemon.this.numMoves.clear();
            Pokemon.this.ledgeJumps.clear();
            if (game.player.currPokemon == Pokemon.this) {
                game.player.currPokemon = game.player.pokemon.get(0);
            }
            game.actionStack.remove(this);
            Pokemon.this.interiorIndex = game.map.interiorTilesIndex;
            Pokemon pokemon = Pokemon.this;
            Objects.requireNonNull(pokemon);
            game.insertAction(new Standing());
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$UnPause.class */
    public class UnPause extends Action {
        public Action.Layer layer = Action.Layer.map_130;
        int moveTimer = 0;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public UnPause() {
            super(new Object[0]);
            Pokemon.this = this$0;
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            if (game.type == Game.Type.CLIENT) {
                game.client.sendTCP(new Network.PausePokemon(game.player.network.id, Pokemon.this.position, false));
            }
            game.actionStack.remove(this);
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$SetStat.class */
    public class SetStat extends Action {
        public Action.Layer layer = Action.Layer.map_5000;
        String stat;
        int setTo;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public SetStat(String stat, int setTo, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.stat = stat;
            this.setTo = setTo;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            Pokemon.this.currentStats.put(this.stat, Integer.valueOf(this.setTo));
            System.out.println(Pokemon.this.currentStats.get(this.stat));
            game.actionStack.remove(this);
            game.insertAction(this.nextAction);
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$SetNickname.class */
    public class SetNickname extends Action {
        Color prevColor = new Color();
        int avatarAnimCounter = 0;
        HashMap<Integer, Character> alphanumericKeys = new HashMap<>();
        HashMap<Integer, Character> alphanumericKeysShift = new HashMap<>();
        ArrayList<Character> text = new ArrayList<>();
        int backspaceTimer = 0;
        public boolean done = false;
        public boolean disabled = false;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public SetNickname(Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            char[] textArray = "ABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
            for (int i = 0; i < textArray.length; i++) {
                this.alphanumericKeys.put(Integer.valueOf(Input.Keys.valueOf(String.valueOf(textArray[i]))), Character.valueOf(String.valueOf(textArray[i]).toLowerCase(Locale.ROOT).charAt(0)));
                this.alphanumericKeysShift.put(Integer.valueOf(Input.Keys.valueOf(String.valueOf(textArray[i]))), Character.valueOf(textArray[i]));
            }
            char[] textArray2 = "1234567890".toCharArray();
            for (int i2 = 0; i2 < textArray2.length; i2++) {
                this.alphanumericKeys.put(Integer.valueOf(Input.Keys.valueOf(String.valueOf(textArray2[i2]))), Character.valueOf(textArray2[i2]));
                this.alphanumericKeysShift.put(Integer.valueOf(Input.Keys.valueOf(String.valueOf(textArray2[i2]))), Character.valueOf(textArray2[i2]));
            }
            this.alphanumericKeys.put(56, '.');
            this.alphanumericKeysShift.put(76, '?');
            this.alphanumericKeysShift.put(8, '!');
            for (char c : this$0.nickname.toCharArray()) {
                this.text.add(Character.valueOf(c));
            }
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "gui";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return Action.Layer.gui_104;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            game.insertAction(new DisplayText(game, "Press enter to set", (String) null, true, false, (Action) null));
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            int i = 0;
            int j = 0;
            int k = 0;
            while (k < this.text.size()) {
                char character = this.text.get(k).charValue();
                if (character == ' ' && k + 1 < this.text.size()) {
                    int length = 1;
                    char nextChar = this.text.get(k + 1).charValue();
                    while (nextChar != ' ' && k + length < this.text.size()) {
                        length++;
                        nextChar = this.text.get(k + length).charValue();
                    }
                    if (i + length > 20 && j < 5) {
                        i = -1;
                        j++;
                    }
                }
                SpriteProxy letterSprite = game.textDict.get(Character.valueOf(character));
                letterSprite.setPosition((float) (8 + (8 * i)), (float) (8 - (16 * j)));
                letterSprite.draw(game.uiBatch);
                i++;
                if (i > 20) {
                    i = 0;
                    j++;
                }
                k++;
            }
            if (this.avatarAnimCounter >= 12) {
                game.uiBatch.draw(game.textDict.get('_'), (float) (8 + (8 * i)), (float) (8 - (16 * j)));
            }
            if (this.done) {
                game.actionStack.remove(this);
            }
            if (!this.disabled) {
                if (!Gdx.input.isKeyPressed(67)) {
                    this.backspaceTimer = 0;
                } else if (this.backspaceTimer < 30) {
                    this.backspaceTimer++;
                }
                if ((this.backspaceTimer >= 30 || Gdx.input.isKeyJustPressed(67)) && this.text.size() > 0) {
                    this.text.remove(this.text.size() - 1);
                }
                if (Gdx.input.isKeyJustPressed(66)) {
                    this.disabled = true;
                    String allText = "";
                    Iterator<Character> it = this.text.iterator();
                    while (it.hasNext()) {
                        allText = allText + it.next().charValue();
                    }
                    game.insertAction(new DisplayText.Clear(game, new WaitFrames(game, 3, new DisplayText(game, "Keep changes?", (String) null, true, false, (Action) new DrawYesNoMenu(null, new SetField(this, "done", true, new DisplayText.Clear(game, new WaitFrames(game, 3, new SetField(Pokemon.this, "nickname", allText, new PlayMusic("coin1", 0.6f, new WaitFrames(game, 10, this.nextAction)))))), new SetField(this, "done", true, new DisplayText.Clear(game, new WaitFrames(game, 10, this.nextAction))))))));
                }
                if (i < 10) {
                    if (Gdx.input.isKeyJustPressed(62)) {
                        this.text.add(' ');
                    }
                    if (Gdx.input.isKeyPressed(59) || Gdx.input.isKeyPressed(60)) {
                        for (Integer key : this.alphanumericKeysShift.keySet()) {
                            if (Gdx.input.isKeyJustPressed(key.intValue())) {
                                this.text.add(this.alphanumericKeysShift.get(key));
                            }
                        }
                    } else {
                        for (Integer key2 : this.alphanumericKeys.keySet()) {
                            if (Gdx.input.isKeyJustPressed(key2.intValue())) {
                                this.text.add(this.alphanumericKeys.get(key2));
                            }
                        }
                    }
                    this.avatarAnimCounter--;
                    if (this.avatarAnimCounter <= 0) {
                        this.avatarAnimCounter = 24;
                    }
                }
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Follow.class */
    public class Follow extends Action {
        Player player;
        Tile targetTile;
        public Action.Layer layer = Action.Layer.map_151;
        boolean alternate = true;
        boolean onPlayer = false;
        private Vector2 pos = new Vector2();

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Follow(Player player) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.player = player;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            Pokemon.this.standingAction = this;
            Pokemon.this.dirFacing = this.player.dirFacing;
            Vector2 pos = this.player.facingPos(Player.oppDirs.get(this.player.dirFacing));
            if (game.map.tiles.get(pos) == null || game.map.tiles.get(pos).isSolid || game.map.tiles.get(pos).isLedge) {
                Pokemon.this.position = this.player.position.cpy();
                this.onPlayer = true;
            } else {
                Pokemon.this.position = pos;
            }
            Pokemon.this.mapTiles = game.map.tiles;
            Pokemon.this.moveDirs.clear();
            Pokemon.this.numMoves.clear();
            Pokemon.this.ledgeJumps.clear();
            Pokemon pokemon = Pokemon.this;
            Objects.requireNonNull(pokemon);
            game.insertAction(new DrawLower(true));
            Pokemon pokemon2 = Pokemon.this;
            Objects.requireNonNull(pokemon2);
            game.insertAction(new DrawUpper(true));
            Tile currTile = Pokemon.this.mapTiles.get(Pokemon.this.position);
            Pokemon.this.inWater = false;
            if (currTile != null && currTile.name.contains("water") && !currTile.name.contains("_tidal")) {
                Pokemon.this.inWater = true;
            }
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            Action action;
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            Pokemon.this.mapTiles = game.map.tiles;
            if (Pokemon.this.moveDirs.size() > 0) {
                String moveDir = Pokemon.this.moveDirs.remove(0);
                float numMove = Pokemon.this.numMoves.remove(0).floatValue();
                int ledgeJump = 0;
                if (Pokemon.this.ledgeJumps.size() > 0) {
                    ledgeJump = Pokemon.this.ledgeJumps.remove(0).intValue();
                }
                this.targetTile = Pokemon.this.mapTiles.get(Pokemon.this.facingPos(this.pos, Pokemon.this.dirFacing));
                if (!this.onPlayer) {
                    game.actionStack.remove(this);
                    if (this.targetTile != null && this.targetTile.name.equals("ice2")) {
                        Pokemon pokemon = Pokemon.this;
                        Objects.requireNonNull(pokemon);
                        action = new Sliding(Pokemon.this.dirFacing, this);
                    } else if (ledgeJump <= 0) {
                        Pokemon pokemon2 = Pokemon.this;
                        Objects.requireNonNull(pokemon2);
                        action = new Moving(Pokemon.this.dirFacing, 1, numMove, this.alternate, true, this);
                    } else {
                        Pokemon pokemon3 = Pokemon.this;
                        Objects.requireNonNull(pokemon3);
                        action = new LedgeJump(Pokemon.this.dirFacing, ledgeJump, true, this);
                    }
                    this.alternate = !this.alternate;
                    game.insertAction(action);
                    Pokemon.this.standingAction = action;
                }
                this.onPlayer = false;
                Pokemon.this.dirFacing = moveDir;
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$FollowPath.class */
    public class FollowPath extends Action {
        Tile targetTile;
        public Action.Layer layer = Action.Layer.map_151;
        boolean alternate = true;
        private Vector2 pos = new Vector2();

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public FollowPath(Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.nextAction = nextAction;
            this$0.standingAction = this;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            boolean isSolid;
            Action action;
            if (Pokemon.this.moveDirs.size() > 0) {
                String moveDir = Pokemon.this.moveDirs.remove(0);
                float numMove = Pokemon.this.numMoves.remove(0).floatValue();
                Pokemon.this.dirFacing = moveDir;
                Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                int ledgeJump = 0;
                if (Pokemon.this.ledgeJumps.size() > 0) {
                    ledgeJump = Pokemon.this.ledgeJumps.remove(0).intValue();
                }
                this.targetTile = Pokemon.this.mapTiles.get(Pokemon.this.facingPos(this.pos, Pokemon.this.dirFacing));
                if (!Pokemon.this.inWater) {
                    isSolid = this.targetTile == null || this.targetTile.isSolid;
                } else if (Pokemon.onlySwim.contains(Pokemon.this.specie.name)) {
                    isSolid = this.targetTile == null || !this.targetTile.isWater;
                } else {
                    isSolid = this.targetTile != null && !this.targetTile.isWater && this.targetTile.isSolid;
                }
                if (this.targetTile == null || isSolid || this.targetTile.isLedge || this.targetTile.name.contains("door") || this.targetTile.nameUpper.contains("gate") || this.targetTile.nameUpper.contains("door") || game.map.pokemon.containsKey(Pokemon.this.facingPos(this.pos, Pokemon.this.dirFacing)) || game.player.position.equals(Pokemon.this.facingPos(this.pos, Pokemon.this.dirFacing))) {
                    game.actionStack.remove(this);
                    Pokemon.this.standingAction = this.nextAction;
                    game.insertAction(this.nextAction);
                    return;
                }
                if (this.targetTile.name.equals("ice2")) {
                    Pokemon pokemon = Pokemon.this;
                    Objects.requireNonNull(pokemon);
                    action = new Sliding(Pokemon.this.dirFacing, this);
                } else if (ledgeJump <= 0) {
                    Pokemon pokemon2 = Pokemon.this;
                    Objects.requireNonNull(pokemon2);
                    action = new Moving(Pokemon.this.dirFacing, 1, numMove, this.alternate, false, this);
                } else {
                    Pokemon pokemon3 = Pokemon.this;
                    Objects.requireNonNull(pokemon3);
                    action = new LedgeJump(Pokemon.this.dirFacing, ledgeJump, false, this);
                }
                this.alternate = !this.alternate;
                game.actionStack.remove(this);
                game.insertAction(action);
                Pokemon.this.standingAction = action;
                return;
            }
            game.actionStack.remove(this);
            Pokemon.this.standingAction = this.nextAction;
            game.insertAction(this.nextAction);
        }
    }

    /* access modifiers changed from: package-private */
    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$LedgeJump.class */
    public class LedgeJump extends Action {
        float xDist;
        float yDist;
        Vector2 initialPos;
        Vector2 targetPos;
        Vector2 shadowPos;
        Sprite shadow;
        int speed;
        String dirFacing;
        boolean isFollowing;
        public Action.Layer layer = Action.Layer.map_131;
        int timer1 = 0;
        ArrayList<Integer> yMovesList = new ArrayList<>();
        ArrayList<Map<String, Sprite>> spriteAnim = new ArrayList<>();

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public LedgeJump(String dirFacing, int speed, boolean isFollowing, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.speed = 1;
            this.dirFacing = dirFacing;
            this.speed = speed;
            this.isFollowing = isFollowing;
            this.nextAction = nextAction;
            this.initialPos = new Vector2(this$0.position);
            if (this$0.dirFacing.equals("up")) {
                this.targetPos = new Vector2(this$0.position.x, this$0.position.y + ((float) (32 / this.speed)));
            } else if (this$0.dirFacing.equals("down")) {
                this.targetPos = new Vector2(this$0.position.x, this$0.position.y - ((float) (32 / this.speed)));
            } else if (this$0.dirFacing.equals("left")) {
                this.targetPos = new Vector2(this$0.position.x - ((float) (32 / this.speed)), this$0.position.y);
            } else if (this$0.dirFacing.equals("right")) {
                this.targetPos = new Vector2(this$0.position.x + ((float) (32 / this.speed)), this$0.position.y);
            }
            this.shadow = new Sprite(TextureCache.get(Gdx.files.internal("shadow1.png")), 0, 0, 16, 16);
            this.shadowPos = this.initialPos.cpy();
            this.yMovesList.add(4);
            this.yMovesList.add(2);
            this.yMovesList.add(2);
            this.yMovesList.add(2);
            this.yMovesList.add(1);
            this.yMovesList.add(1);
            this.yMovesList.add(0);
            this.yMovesList.add(0);
            this.yMovesList.add(-1);
            this.yMovesList.add(-1);
            this.yMovesList.add(-1);
            this.yMovesList.add(-1);
            this.yMovesList.add(-2);
            this.yMovesList.add(-3);
            this.yMovesList.add(-3);
            this.yMovesList.add(0);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.movingSprites);
            this.spriteAnim.add(this$0.movingSprites);
            this.spriteAnim.add(this$0.movingSprites);
            this.spriteAnim.add(this$0.movingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.altMovingSprites);
            this.spriteAnim.add(this$0.altMovingSprites);
            this.spriteAnim.add(this$0.altMovingSprites);
            this.spriteAnim.add(this$0.altMovingSprites);
            this.spriteAnim.add(this$0.standingSprites);
            this.spriteAnim.add(this$0.standingSprites);
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            if (this.speed == 2) {
                game.insertAction(new PlayMusic("ledge2", (Action) null));
            } else {
                game.insertAction(new PlayMusic("ledge1", (Action) null));
            }
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.timer1 < 32 / this.speed) {
                if (this.dirFacing.equals("up")) {
                    Pokemon.this.position.y += 1.0f;
                    this.shadowPos.y += 1.0f;
                } else if (this.dirFacing.equals("down")) {
                    Pokemon.this.position.y -= 1.0f;
                    this.shadowPos.y -= 1.0f;
                } else if (this.dirFacing.equals("left")) {
                    Pokemon.this.position.x -= 1.0f;
                    this.shadowPos.x -= 1.0f;
                } else if (this.dirFacing.equals("right")) {
                    Pokemon.this.position.x += 1.0f;
                    this.shadowPos.x += 1.0f;
                }
                if (this.timer1 % 2 == 1) {
                    Pokemon.this.position.y += (float) this.yMovesList.remove(0).intValue();
                    Pokemon.this.currOwSprite = this.spriteAnim.remove(0).get(this.dirFacing);
                    for (int i = 0; i < this.speed - 1; i++) {
                        this.yMovesList.remove(0);
                        this.spriteAnim.remove(0);
                    }
                }
            } else {
                Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(this.dirFacing);
            }
            game.mapBatch.draw(this.shadow, this.shadowPos.x, this.shadowPos.y - 6.0f);
            if (this.timer1 >= 38 / this.speed) {
                Pokemon.this.position.set(this.targetPos);
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
                Pokemon.this.standingAction = this.nextAction;
                if (!this.isFollowing) {
                    Pokemon.this.checkHabitat(game);
                }
                this.nextAction.step(game);
            }
            this.timer1++;
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Shadowed.class */
    public class Shadowed extends Action {
        public Action.Layer layer = Action.Layer.map_107;
        public int timer = 0;
        public int timesMoved = 0;
        boolean checkEncounter = false;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Shadowed(Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            Pokemon.this.standingAction = this;
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            game.insertAction(new DrawShadow());
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (game.playerCanMove) {
                if (!game.player.isSleeping) {
                    game.actionStack.remove(this);
                    Pokemon.this.removeDrawActions(game);
                    return;
                }
                if (this.checkEncounter) {
                    this.checkEncounter = false;
                    if (Pokemon.this.position.dst2(game.player.position) < 64.0f && !game.player.currFieldMove.equals("FLY") && game.playerCanMove) {
                        game.playerCanMove = false;
                        game.battle.oppPokemon = Pokemon.this;
                        game.player.setCurrPokemon();
                        game.insertAction(new WaitFrames(game, 16, new SetField(game.musicController, "startBattle", "wild", Battle.getIntroAction(game))));
                        game.insertAction(new WaitFrames(game, 500, new SetField(game.player, "isSleeping", false, new SetField(game.player, "acceptInput", true, new SetField(game.player, "drawSleepingBag", false, null)))));
                        return;
                    }
                }
                this.timer--;
                if (this.timer <= 0) {
                    this.timer = (Game.rand.nextInt(2) + 3) * 60;
                    if (this.timesMoved < 3) {
                        this.timesMoved++;
                    } else if (this.timesMoved < 5) {
                        this.timer = 30;
                    } else {
                        this.timer = 10;
                    }
                    ArrayList<String> preferredMoves = new ArrayList<>();
                    if (Pokemon.this.position.x - game.player.position.x < Pokemon.this.position.y - game.player.position.y) {
                        if (game.player.position.y < Pokemon.this.position.y) {
                            preferredMoves.add("down");
                            preferredMoves.add("right");
                        } else {
                            preferredMoves.add("right");
                            preferredMoves.add("up");
                        }
                    } else if (game.player.position.x < Pokemon.this.position.x) {
                        preferredMoves.add("left");
                        preferredMoves.add("down");
                    } else {
                        preferredMoves.add("up");
                        preferredMoves.add("left");
                    }
                    Iterator<String> it = preferredMoves.iterator();
                    if (it.hasNext()) {
                        String move = it.next();
                        Vector2 startPos = Pokemon.this.position.cpy().add(-80.0f, -80.0f);
                        startPos.x = (float) (((int) startPos.x) - (((int) startPos.x) % 16));
                        startPos.y = (float) (((int) startPos.y) - (((int) startPos.y) % 16));
                        Vector2 endPos = Pokemon.this.position.cpy().add(80.0f, 80.0f);
                        endPos.x = (float) (((int) endPos.x) - (((int) endPos.x) % 16));
                        endPos.y = (float) (((int) endPos.y) - (((int) endPos.y) % 16));
                        Vector2 currPos = new Vector2(startPos.x, startPos.y);
                        while (currPos.y < endPos.y) {
                            Tile tile = game.map.tiles.get(currPos);
                            currPos.x += 16.0f;
                            if (currPos.x > endPos.x) {
                                currPos.x = startPos.x;
                                currPos.y += 16.0f;
                            }
                            if (tile != null) {
                                if (!tile.nameUpper.contains("campfire")) {
                                    if (tile.items != null && tile.items.containsKey("torch") && Pokemon.this.position.dst2(tile.position) < 1024.0f) {
                                        return;
                                    }
                                    if (game.map.pokemon.containsKey(tile.position)) {
                                        if (game.map.pokemon.get(tile.position).hms.contains("FLASH")) {
                                            return;
                                        }
                                    } else if (game.player.hmPokemon != null && Pokemon.this.position.dst2(game.player.position) < 4096.0f && game.player.hmPokemon.hms.contains("FLASH")) {
                                        return;
                                    }
                                } else {
                                    return;
                                }
                            }
                        }
                        Pokemon.this.dirFacing = move;
                        game.actionStack.remove(this);
                        Pokemon pokemon = Pokemon.this;
                        Objects.requireNonNull(pokemon);
                        Action action = new Moving(Pokemon.this.dirFacing, 1, 1.5f, true, true, this);
                        game.insertAction(action);
                        Pokemon.this.standingAction = action;
                        this.checkEncounter = true;
                    }
                }
            }
        }

        /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Shadowed$DrawShadow.class */
        class DrawShadow extends DrawUpper {
            public Action.Layer layer = Action.Layer.map_130;
            Texture texture = TextureCache.get(Gdx.files.internal("shadow1.png"));

            @Override // com.corona.game.Action
            public String getCamera() {
                return "map";
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public Action.Layer getLayer() {
                return this.layer;
            }

            /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
            public DrawShadow() {
                super();
                Shadowed.this = this$1;
                Pokemon.this.drawUpper = this;
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public void firstStep(Game game) {
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public void step(Game game) {
                game.mapBatch.draw(this.texture, Pokemon.this.position.x, Pokemon.this.position.y - 1.0f);
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Cacturnt.class */
    public class Cacturnt extends Action {
        public Action.Layer layer = Action.Layer.map_107;
        public int aggroTimer = 0;
        public boolean alternate = false;
        public int campfireDespawn = 0;
        private Vector2 newPos = new Vector2();
        Sprite tornadoSprite = new Sprite(TextureCache.get(Gdx.files.internal("tornado_sheet1.png")), 0, 0, 16, 16);

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Cacturnt(Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            game.map.pokemon.put(Pokemon.this.position.cpy(), Pokemon.this);
            Pokemon.this.standingAction = this;
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            Pokemon pokemon = Pokemon.this;
            Objects.requireNonNull(pokemon);
            game.insertAction(new DrawLower());
            Pokemon pokemon2 = Pokemon.this;
            Objects.requireNonNull(pokemon2);
            game.insertAction(new DrawUpper());
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (game.playerCanMove) {
                if (this.campfireDespawn > 0) {
                    if (this.campfireDespawn == 60) {
                        Pokemon.this.dirFacing = "down";
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                        Pokemon pokemon = Pokemon.this;
                        Objects.requireNonNull(pokemon);
                        game.insertAction(new CactusSpawn(null, null));
                    }
                    if (this.campfireDespawn < 40) {
                        if (this.campfireDespawn % 4 == 3) {
                            this.tornadoSprite.setRegion(0, 0, 18, 16);
                        } else if (this.campfireDespawn % 4 == 1) {
                            this.tornadoSprite.setRegion(18, 0, 18, 16);
                        }
                        game.mapBatch.draw(this.tornadoSprite, Pokemon.this.position.x - 2.0f, Pokemon.this.position.y + 2.0f);
                    }
                    if (this.campfireDespawn <= 1) {
                        game.actionStack.remove(this);
                        game.map.pokemon.remove(Pokemon.this.position);
                        Pokemon.this.removeDrawActions(game);
                        boolean foundCacturnt = false;
                        Iterator<Action> it = game.actionStack.iterator();
                        while (true) {
                            if (it.hasNext()) {
                                if (it.next() instanceof Cacturnt) {
                                    foundCacturnt = true;
                                    break;
                                }
                            } else {
                                break;
                            }
                        }
                        if (!foundCacturnt) {
                            game.musicController.nightAlert = false;
                            game.musicController.resumeOverworldMusic = true;
                        }
                    }
                    this.campfireDespawn--;
                } else if (game.map.timeOfDay.equals("day")) {
                    this.campfireDespawn = 60;
                } else {
                    if (this.aggroTimer > 240) {
                        this.aggroTimer = 0;
                    }
                    this.aggroTimer++;
                    if (this.aggroTimer == 1) {
                        Pokemon pokemon2 = Pokemon.this;
                        Objects.requireNonNull(pokemon2);
                        game.insertAction(new Emote("skull", null));
                    }
                    float dst2 = Pokemon.this.position.dst2(game.player.position);
                    if (this.aggroTimer == 1) {
                        game.insertAction(new PlayMusic(Pokemon.this, true, (Action) null));
                    }
                    if (this.aggroTimer < 4) {
                        if (this.aggroTimer == 0) {
                            game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                        }
                        Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 8) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 12) {
                        if (this.aggroTimer == 8) {
                            game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                        }
                        Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 16) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 20) {
                        if (this.aggroTimer == 16) {
                            game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                        }
                        Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 24) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 28) {
                        if (this.aggroTimer == 24) {
                            game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                        }
                        Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.aggroTimer < 32) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else {
                        ArrayList<String> preferredMoves = new ArrayList<>();
                        if (Pokemon.this.position.x - game.player.position.x < Pokemon.this.position.y - game.player.position.y) {
                            if (game.player.position.y < Pokemon.this.position.y) {
                                preferredMoves.add("down");
                                preferredMoves.add("right");
                            } else {
                                preferredMoves.add("right");
                                preferredMoves.add("up");
                            }
                        } else if (game.player.position.x < Pokemon.this.position.x) {
                            preferredMoves.add("left");
                            preferredMoves.add("down");
                        } else {
                            preferredMoves.add("up");
                            preferredMoves.add("left");
                        }
                        if (dst2 < 64.0f && this.aggroTimer > 32 && !game.player.currFieldMove.equals("FLY")) {
                            if (game.player.isSleeping) {
                                game.player.isSleeping = false;
                                if (game.player.sleepingDir == null) {
                                    game.player.drawSleepingBag = false;
                                    game.player.acceptInput = true;
                                } else {
                                    game.player.sleepingDir = null;
                                }
                            }
                            if (game.player.acceptInput) {
                                game.playerCanMove = false;
                                this.aggroTimer = 0;
                                game.musicController.startBattle = "wild";
                                game.battle.oppPokemon = Pokemon.this;
                                game.player.setCurrPokemon();
                                game.insertAction(Battle.getIntroAction(game));
                                return;
                            }
                        }
                        Iterator<String> it2 = preferredMoves.iterator();
                        while (it2.hasNext()) {
                            String move = it2.next();
                            this.newPos = Pokemon.this.facingPos(this.newPos, move);
                            Tile facingTile = Pokemon.this.mapTiles.get(this.newPos);
                            Tile currTile = Pokemon.this.mapTiles.get(Pokemon.this.position);
                            boolean isLedge = (facingTile != null && facingTile.isLedge) || (currTile != null && currTile.isLedge && currTile.ledgeDir().equals("up") && move.equals("up"));
                            if (!facingTile.isSolid && !isLedge && !facingTile.name.contains("door") && !facingTile.nameUpper.contains("gate") && !facingTile.nameUpper.contains("door") && !game.map.pokemon.containsKey(this.newPos)) {
                                Vector2 startPos = Pokemon.this.position.cpy().add(-80.0f, -80.0f);
                                startPos.x = (float) (((int) startPos.x) - (((int) startPos.x) % 16));
                                startPos.y = (float) (((int) startPos.y) - (((int) startPos.y) % 16));
                                Vector2 endPos = Pokemon.this.position.cpy().add(80.0f, 80.0f);
                                endPos.x = (float) (((int) endPos.x) - (((int) endPos.x) % 16));
                                endPos.y = (float) (((int) endPos.y) - (((int) endPos.y) % 16));
                                Vector2 currPos = new Vector2(startPos.x, startPos.y);
                                while (currPos.y < endPos.y) {
                                    Tile tile = game.map.tiles.get(currPos);
                                    currPos.x += 16.0f;
                                    if (currPos.x > endPos.x) {
                                        currPos.x = startPos.x;
                                        currPos.y += 16.0f;
                                    }
                                    if (tile != null) {
                                        if (tile.nameUpper.contains("campfire")) {
                                            this.campfireDespawn = 200;
                                            return;
                                        } else if (tile.items != null && tile.items.containsKey("torch") && Pokemon.this.position.dst2(tile.position) < 1024.0f) {
                                            this.campfireDespawn = 200;
                                            return;
                                        } else if (game.map.pokemon.containsKey(tile.position)) {
                                            if (game.map.pokemon.get(tile.position).hms.contains("FLASH")) {
                                                this.campfireDespawn = 200;
                                                return;
                                            }
                                        } else if (game.player.hmPokemon != null && Pokemon.this.position.dst2(game.player.position) < 4096.0f && game.player.hmPokemon.hms.contains("FLASH")) {
                                            this.campfireDespawn = 200;
                                            return;
                                        }
                                    }
                                }
                                if (game.map.pokemon.containsKey(Pokemon.this.position) && game.map.pokemon.get(Pokemon.this.position) == Pokemon.this) {
                                    game.map.pokemon.remove(Pokemon.this.position);
                                }
                                game.map.pokemon.put(this.newPos.cpy(), Pokemon.this);
                                Pokemon.this.dirFacing = move;
                                game.actionStack.remove(this);
                                Pokemon pokemon3 = Pokemon.this;
                                Objects.requireNonNull(pokemon3);
                                Action action = new Moving(pokemon3, 1, 1.5f, this.alternate, this);
                                this.alternate = !this.alternate;
                                game.insertAction(action);
                                Pokemon.this.standingAction = action;
                                return;
                            }
                        }
                    }
                }
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$CactusSpawn.class */
    public class CactusSpawn extends Action {
        Tile tile;
        public Action.Layer layer = Action.Layer.map_116;
        int timer = 0;

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public CactusSpawn(Tile tile, Action nextAction) {
            super(new Object[0]);
            Pokemon.this = this$0;
            this.tile = tile;
            this.nextAction = nextAction;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (this.timer % 4 < 2) {
                Pokemon.this.drawThisFrame = false;
            } else {
                Pokemon.this.drawThisFrame = true;
            }
            if (this.timer > 60) {
                Pokemon.this.drawThisFrame = true;
                game.actionStack.remove(this);
                game.insertAction(this.nextAction);
            }
            this.timer++;
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Burrowed.class */
    public class Burrowed extends Action {
        Sprite spritePart;
        public Action.Layer layer = Action.Layer.map_119;
        int whirlTimer = 0;
        boolean popOut = false;
        int jumpTimer = 0;
        int offsetY = 0;
        Sprite whirlpoolSprite = new Sprite(TextureCache.get(Gdx.files.internal("whirlpool_desert2.png")), 0, 0, 16, 16);
        Sprite sandSprite = new Sprite(TextureCache.get(Gdx.files.internal("grass_over_sheet3.png")), 0, 0, 16, 16);
        Sprite trapinchSprite = new Sprite(TextureCache.get(Gdx.files.internal("trapinch_ow1.png")), 0, 0, 16, 16);

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Burrowed() {
            super(new Object[0]);
            Pokemon.this = this$0;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            Pokemon.this.dirFacing = "right";
            Pokemon.this.currOwSprite = this.trapinchSprite;
            Pokemon.this.drawUpper = new DrawUpper();
            Pokemon.this.standingAction = this;
            game.map.burrowedPokemon.put(Pokemon.this.position.cpy(), Pokemon.this);
            game.actionStack.remove(this);
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
        }

        /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Burrowed$DrawUpper.class */
        class DrawUpper extends DrawUpper {
            public Action.Layer layer = Action.Layer.map_114;
            Sprite spritePart = new Sprite();

            @Override // com.corona.game.Action
            public String getCamera() {
                return "map";
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public Action.Layer getLayer() {
                return this.layer;
            }

            /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
            public DrawUpper() {
                super();
                Burrowed.this = this$1;
                Pokemon.this.drawUpper = this;
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public void firstStep(Game game) {
            }

            @Override // com.corona.game.Pokemon.DrawUpper, com.corona.game.Action
            public void step(Game game) {
            }

            @Override // com.corona.game.Pokemon.DrawUpper
            public void draw(Game game) {
                if (Pokemon.this.mapTiles == game.map.tiles && game.player.position.equals(Pokemon.this.position) && !game.player.currFieldMove.equals("FLY")) {
                    Burrowed.this.popOut = true;
                }
                if (Burrowed.this.popOut) {
                    if (Burrowed.this.jumpTimer < 50) {
                        Burrowed.this.jumpTimer++;
                        if (Burrowed.this.jumpTimer % 8 == 0) {
                            game.insertAction(new PlayMusic("move_object", 0.6f, true, null));
                        }
                    } else if (Burrowed.this.jumpTimer < 53) {
                        Burrowed.this.jumpTimer++;
                        Burrowed.this.offsetY += 4;
                        if (Burrowed.this.jumpTimer % 8 < 4) {
                            Burrowed.this.trapinchSprite.setRegion(0, 0, 16, 16);
                        } else {
                            Burrowed.this.trapinchSprite.setRegion(16, 0, 16, 16);
                        }
                    } else if (Burrowed.this.jumpTimer < 66) {
                        Burrowed.this.jumpTimer++;
                    } else if (!game.player.position.equals(Pokemon.this.position)) {
                        Burrowed.this.jumpTimer++;
                        if (Burrowed.this.jumpTimer >= 120 && Burrowed.this.jumpTimer < 156) {
                            if (Burrowed.this.jumpTimer % 8 < 4) {
                                Burrowed.this.trapinchSprite.setRegion(0, 0, 16, 16);
                            } else {
                                Burrowed.this.trapinchSprite.setRegion(16, 0, 16, 16);
                            }
                            if (Burrowed.this.jumpTimer % 8 == 0) {
                                game.insertAction(new PlayMusic("move_object", 0.6f, true, null));
                            }
                            if (Burrowed.this.jumpTimer >= 141) {
                                Burrowed.this.offsetY--;
                            }
                        }
                        if (Burrowed.this.jumpTimer >= 152) {
                            Burrowed.this.popOut = false;
                            Burrowed.this.jumpTimer = 0;
                        }
                    }
                    if (Burrowed.this.jumpTimer >= 63 && game.player.position.equals(Pokemon.this.position) && game.playerCanMove) {
                        game.playerCanMove = false;
                        game.musicController.startBattle = "wild";
                        game.battle.oppPokemon = Pokemon.this;
                        game.player.setCurrPokemon();
                        game.insertAction(Battle.getIntroAction(game));
                    }
                    if (Burrowed.this.jumpTimer == 34) {
                        game.insertAction(new PlayMusic(Pokemon.this, (Action) null));
                    }
                }
                if (Burrowed.this.jumpTimer > 0) {
                    if (Burrowed.this.whirlTimer == 0) {
                        Burrowed.this.whirlpoolSprite.setRegion(0, 0, 16, 16);
                    } else if (Burrowed.this.whirlTimer == 40) {
                        Burrowed.this.whirlpoolSprite.setRegion(16, 0, 16, 16);
                    }
                    game.mapBatch.draw(Burrowed.this.whirlpoolSprite, Pokemon.this.position.x, Pokemon.this.position.y);
                }
                Burrowed.this.whirlTimer++;
                if (Burrowed.this.whirlTimer >= 80) {
                    Burrowed.this.whirlTimer = 0;
                }
                this.spritePart.set(Pokemon.this.currOwSprite);
                this.spritePart.setRegionHeight(Burrowed.this.offsetY);
                game.mapBatch.draw(this.spritePart, Pokemon.this.position.x, Pokemon.this.position.y + 6.0f);
                if (Burrowed.this.jumpTimer >= 50 && Burrowed.this.jumpTimer < 66) {
                    if (Burrowed.this.jumpTimer == 50) {
                        Burrowed.this.sandSprite.setRegion(0, 0, 16, 16);
                    } else if (Burrowed.this.jumpTimer == 58) {
                        Burrowed.this.sandSprite.setRegion(16, 0, 16, 16);
                    }
                    game.mapBatch.draw(Burrowed.this.sandSprite, Pokemon.this.position.x, Pokemon.this.position.y + 6.0f);
                }
            }
        }
    }

    /* loaded from: pokewilds.jar:com/pkmngen/game/Pokemon$Standing.class */
    public class Standing extends Action {
        public Action.Layer layer = Action.Layer.map_130;
        int moveTimer = 0;
        int runTimer = 0;
        int danceCounter = 240;
        boolean alternate = true;
        public int aggroTimer = 0;
        public boolean justAggroed = true;
        public boolean isEgg = false;
        public int losTimer = 0;
        public String nearbyDir = null;
        public String nearbyDir2 = null;
        public int charmTimer = 0;
        public int lungeCounter = 0;
        public String lungeDir = null;
        private Vector2 pos1 = new Vector2();
        private Vector2 pos2 = new Vector2();
        private Vector2 pos3 = new Vector2();

        /* JADX INFO: 'super' call moved to the top of the method (can break code semantics) */
        public Standing() {
            super(new Object[0]);
            Pokemon.this = this$0;
        }

        @Override // com.corona.game.Action
        public String getCamera() {
            return "map";
        }

        @Override // com.corona.game.Action
        public Action.Layer getLayer() {
            return this.layer;
        }

        @Override // com.corona.game.Action
        public void firstStep(Game game) {
            this.moveTimer = game.map.rand.nextInt(180) + 60;
            game.map.pokemon.put(Pokemon.this.position.cpy(), Pokemon.this);
            Pokemon.this.standingAction = this;
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            Pokemon pokemon = Pokemon.this;
            Objects.requireNonNull(pokemon);
            game.insertAction(new DrawLower());
            Pokemon pokemon2 = Pokemon.this;
            Objects.requireNonNull(pokemon2);
            game.insertAction(new DrawUpper());
            Pokemon.this.checkHabitat(game);
            this.isEgg = Pokemon.this.isEgg;
            Tile currTile = Pokemon.this.mapTiles.get(Pokemon.this.position);
            Pokemon.this.inWater = false;
            if (currTile != null && currTile.name.contains("water") && !currTile.name.contains("_tidal")) {
                Pokemon.this.inWater = true;
            }
        }

        public void localStep(Game game) {
            boolean isSolid;
            String nearbyDir;
            boolean isSolid2;
            if (Pokemon.this.previousOwner == null && Pokemon.this.specie.name.equals("darmanitanzen")) {
                return;
            }
            if (this.isEgg) {
                if (this.danceCounter < 4) {
                    Pokemon.this.spriteOffsetY = 16;
                    Pokemon.this.currOwSprite = Pokemon.this.avatarSprites.get(1);
                } else if (this.danceCounter < 16) {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                } else if (this.danceCounter < 20) {
                    Pokemon.this.spriteOffsetY = 16;
                    Pokemon.this.currOwSprite = Pokemon.this.avatarSprites.get(1);
                } else if (this.danceCounter < 90) {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                } else if (this.danceCounter < 94) {
                    Pokemon.this.spriteOffsetY = 32;
                    Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get("down");
                } else if (this.danceCounter < 98) {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                } else if (this.danceCounter < 102) {
                    Pokemon.this.spriteOffsetY = 48;
                    Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get("down");
                } else if (this.danceCounter < 106) {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                } else if (this.danceCounter < 110) {
                    Pokemon.this.spriteOffsetY = 32;
                    Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get("down");
                } else if (this.danceCounter < 114) {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                } else if (this.danceCounter < 118) {
                    Pokemon.this.spriteOffsetY = 48;
                    Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get("down");
                } else {
                    Pokemon.this.spriteOffsetY = 0;
                    Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get("down");
                }
                this.danceCounter++;
                if (this.danceCounter >= 240 + (30 * (Pokemon.this.happiness - 1))) {
                    this.danceCounter = 0;
                    return;
                }
                return;
            }
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            this.charmTimer++;
            if (this.charmTimer > 240) {
                this.charmTimer = 0;
                Pokemon.this.isCharmed = game.player.currFieldMove.equals("CHARM") && game.player.hmPokemon != null && game.player.hmPokemon.level >= Pokemon.this.level;
                if (Pokemon.this.isCharmed) {
                    Pokemon pokemon = Pokemon.this;
                    Objects.requireNonNull(pokemon);
                    game.insertAction(new Emote("heart", null));
                }
            }
            if (Pokemon.this.aggroPlayer && Pokemon.this.mapTiles == game.map.tiles) {
                if (game.playerCanMove) {
                    if (this.aggroTimer > 240) {
                        this.aggroTimer = 0;
                    }
                    this.aggroTimer++;
                    if (this.aggroTimer == 1) {
                        Pokemon pokemon2 = Pokemon.this;
                        Objects.requireNonNull(pokemon2);
                        game.insertAction(new Emote("skull", null));
                    }
                    float dst2 = Pokemon.this.position.dst2(game.player.position);
                    boolean hasLos = true;
                    if (Pokemon.this.mapTiles != game.map.overworldTiles) {
                        if (dst2 < 16384.0f && this.losTimer <= 0) {
                            Vector2 startPos = this.pos1.set(Pokemon.this.position);
                            Vector2 losVector = this.pos2.set(game.player.position).sub(startPos).nor().scl(16.0f);
                            Vector2 checkPos = this.pos3;
                            while (true) {
                                if (Pokemon.this.position.dst2(startPos) >= dst2) {
                                    break;
                                }
                                startPos.add(losVector);
                                checkPos.set((float) (((int) startPos.x) - (((int) startPos.x) % 16)), (float) (((int) startPos.y) - (((int) startPos.y) % 16)));
                                if (Pokemon.this.mapTiles.get(checkPos) == null) {
                                    hasLos = false;
                                    break;
                                }
                            }
                            if (hasLos) {
                                this.losTimer = 60;
                            }
                        }
                        if (this.losTimer > 0) {
                            this.losTimer--;
                        }
                    }
                    if (dst2 >= 14400.0f || !hasLos || Pokemon.this.isCharmed) {
                        this.justAggroed = true;
                    } else {
                        if (this.justAggroed) {
                            Pokemon pokemon3 = Pokemon.this;
                            Objects.requireNonNull(pokemon3);
                            game.insertAction(new Emote("skull", null));
                            this.aggroTimer = 1;
                            this.justAggroed = false;
                        }
                        if (this.aggroTimer == 1) {
                            if (Pokemon.this.specie.name.equals("dusclops")) {
                                game.insertAction(new PlayMusic("pokemon/cries/" + Pokemon.this.dexNumber, 0.2f, (Action) null));
                            } else {
                                game.insertAction(new PlayMusic(Pokemon.this, (Action) null));
                            }
                        }
                        if (this.aggroTimer < 4) {
                            if (this.aggroTimer == 0) {
                                game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                            }
                            Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 8) {
                            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 12) {
                            if (this.aggroTimer == 8) {
                                game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                            }
                            Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 16) {
                            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 20) {
                            if (this.aggroTimer == 16) {
                                game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                            }
                            Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 24) {
                            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 28) {
                            if (this.aggroTimer == 24) {
                                game.insertAction(new PlayMusic("ride1", 0.5f, true, null));
                            }
                            Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else if (this.aggroTimer < 32) {
                            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                            return;
                        } else {
                            ArrayList<String> preferredMoves = new ArrayList<>();
                            if (Pokemon.this.position.x < game.player.position.x) {
                                preferredMoves.add("right");
                            } else if (Pokemon.this.position.x > game.player.position.x) {
                                preferredMoves.add("left");
                            }
                            if (Pokemon.this.position.y < game.player.position.y) {
                                preferredMoves.add("up");
                            } else if (Pokemon.this.position.y > game.player.position.y) {
                                preferredMoves.add("down");
                            }
                            if (!preferredMoves.isEmpty() && Game.rand.nextInt(256) < 128) {
                                preferredMoves.add(preferredMoves.remove(0));
                            }
                            if (this.lungeCounter <= 0 && dst2 <= 4096.0f && Pokemon.this.specie.name.equals("sharpedo")) {
                                if (((Pokemon.this.dirFacing.equals("down") || Pokemon.this.dirFacing.equals("up")) && Pokemon.this.position.x == game.player.position.x) || ((Pokemon.this.dirFacing.equals("left") || Pokemon.this.dirFacing.equals("right")) && Pokemon.this.position.y == game.player.position.y)) {
                                    this.lungeCounter = 10;
                                    this.lungeDir = Pokemon.this.dirFacing;
                                    this.aggroTimer = 0;
                                    return;
                                }
                            }
                            if (this.lungeCounter > 0) {
                                preferredMoves.clear();
                                preferredMoves.add(this.lungeDir);
                                this.lungeCounter--;
                            }
                            if (dst2 < 64.0f && this.aggroTimer > 32 && !game.player.currFieldMove.equals("FLY")) {
                                if (game.player.isSleeping) {
                                    game.player.isSleeping = false;
                                    if (game.player.sleepingDir == null) {
                                        game.player.drawSleepingBag = false;
                                        game.player.acceptInput = true;
                                    } else {
                                        game.player.sleepingDir = null;
                                    }
                                }
                                if (game.player.acceptInput) {
                                    game.playerCanMove = false;
                                    this.aggroTimer = 0;
                                    game.musicController.startBattle = "wild";
                                    game.battle.oppPokemon = Pokemon.this;
                                    game.player.setCurrPokemon();
                                    game.insertAction(Battle.getIntroAction(game));
                                    return;
                                }
                            }
                            for (int i = 0; i < preferredMoves.size(); i++) {
                                String move = preferredMoves.get(i);
                                Vector2 facingPos = Pokemon.this.facingPos(this.pos1, move);
                                Tile facingTile = Pokemon.this.mapTiles.get(facingPos);
                                Tile currTile = Pokemon.this.mapTiles.get(Pokemon.this.position);
                                boolean isLedge = (facingTile != null && facingTile.isLedge) || (currTile != null && currTile.isLedge && currTile.ledgeDir().equals("up") && move.equals("up"));
                                if (!Pokemon.this.inWater) {
                                    isSolid2 = facingTile == null || facingTile.isSolid;
                                } else if (Pokemon.onlySwim.contains(Pokemon.this.specie.name)) {
                                    isSolid2 = facingTile == null || !facingTile.isWater;
                                } else {
                                    isSolid2 = facingTile != null && !facingTile.isWater && facingTile.isSolid;
                                }
                                if (facingTile != null && !isSolid2 && !isLedge && !facingTile.name.contains("door") && !facingTile.nameUpper.contains("gate") && !facingTile.nameUpper.contains("door") && !game.map.pokemon.containsKey(facingPos)) {
                                    Pokemon.this.dirFacing = move;
                                    game.actionStack.remove(this);
                                    float speed = 1.5f;
                                    if (this.lungeCounter > 0) {
                                        speed = 2.7f;
                                    }
                                    Pokemon pokemon4 = Pokemon.this;
                                    Objects.requireNonNull(pokemon4);
                                    Action action = new Moving(pokemon4, 1, speed, this.alternate, this);
                                    this.alternate = !this.alternate;
                                    game.insertAction(action);
                                    Pokemon.this.standingAction = action;
                                    return;
                                }
                            }
                            return;
                        }
                    }
                } else {
                    return;
                }
            }
            if (Pokemon.this.isSkittish() && this.moveTimer % 32 == 0 && this.runTimer <= 0 && Pokemon.this.previousOwner != game.player && !Pokemon.this.isRunning && !Pokemon.this.isCharmed && Pokemon.this.position.dst2(game.player.position) < 4096.0f) {
                this.runTimer = 180;
            }
            if (this.runTimer > 0 && !Pokemon.this.isRunning) {
                if (this.runTimer == 170) {
                    Pokemon pokemon5 = Pokemon.this;
                    Objects.requireNonNull(pokemon5);
                    game.insertAction(new Emote("!", null));
                    game.insertAction(new PlayMusic("ledge2", (Action) null));
                }
                if (this.runTimer == 110) {
                    Pokemon.this.dirFacing = "left";
                }
                if (this.runTimer == 100) {
                    Pokemon.this.dirFacing = "right";
                }
                if (this.runTimer == 90) {
                    Pokemon.this.dirFacing = "left";
                }
                if (this.runTimer == 80) {
                    Pokemon.this.dirFacing = "right";
                }
                if (this.runTimer == 70) {
                    Pokemon.this.isRunning = true;
                }
                this.runTimer--;
            } else if (!Pokemon.this.isRunning || !Pokemon.this.canMove) {
                if (Pokemon.this.hasItem != null) {
                    this.danceCounter++;
                    if (this.danceCounter <= 16) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.danceCounter <= 32) {
                        Pokemon.this.currOwSprite = Pokemon.this.movingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.danceCounter <= 48) {
                        Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                    } else if (this.danceCounter < 64) {
                        Pokemon.this.currOwSprite = Pokemon.this.altMovingSprites.get(Pokemon.this.dirFacing);
                    } else {
                        this.danceCounter = 0;
                    }
                }
                if (Pokemon.this.canMove) {
                    if (!Pokemon.this.moveDirs.isEmpty()) {
                        this.moveTimer = game.map.rand.nextInt(180) + 60;
                        game.actionStack.remove(this);
                        Pokemon pokemon6 = Pokemon.this;
                        Objects.requireNonNull(pokemon6);
                        game.insertAction(new FollowPath(this));
                    } else if (Pokemon.this.friendTimer > 0 || Pokemon.this.friend == null) {
                        if (this.moveTimer <= 0) {
                            if (Pokemon.this.previousOwner != null || !Pokemon.this.specie.name.equals("sigilyph")) {
                                this.nearbyDir = null;
                                this.nearbyDir2 = null;
                                if (Pokemon.this.specie.name.equals("diglett") || Pokemon.this.specie.name.equals("dugtrio") || Pokemon.this.specie.name.equals("sharpedo")) {
                                    this.moveTimer = 1;
                                } else {
                                    Vector2 startPos2 = this.pos1.set(Pokemon.this.position).add(-80.0f, -80.0f);
                                    startPos2.x = (float) (((int) startPos2.x) - (((int) startPos2.x) % 16));
                                    startPos2.y = (float) (((int) startPos2.y) - (((int) startPos2.y) % 16));
                                    Vector2 endPos = this.pos2.set(Pokemon.this.position).add(80.0f, 80.0f);
                                    endPos.x = (float) (((int) endPos.x) - (((int) endPos.x) % 16));
                                    endPos.y = (float) (((int) endPos.y) - (((int) endPos.y) % 16));
                                    Vector2 currPos = this.pos3;
                                    currPos.set(startPos2);
                                    while (currPos.y <= endPos.y) {
                                        Tile tile = Pokemon.this.mapTiles.get(currPos);
                                        Pokemon pokemon7 = game.map.pokemon.get(currPos);
                                        currPos.x += 16.0f;
                                        if (currPos.x > endPos.x) {
                                            currPos.x = startPos2.x;
                                            currPos.y += 16.0f;
                                        }
                                        if (!(tile == null || pokemon7 == null || pokemon7 == Pokemon.this)) {
                                            if (pokemon7.baseSpecie() == null) {
                                                System.out.println("pokemon.specie.name");
                                                System.out.println(pokemon7.specie.name);
                                            }
                                            if (Pokemon.this.baseSpecie() == null) {
                                                System.out.println("Pokemon.this.specie.name");
                                                System.out.println(Pokemon.this.specie.name);
                                            }
                                            boolean sameBaseSpecie = pokemon7.baseSpecie().equals(Pokemon.this.baseSpecie());
                                            if (Pokemon.this.specie.name.equals("tauros")) {
                                                sameBaseSpecie = sameBaseSpecie || pokemon7.baseSpecie().equals("miltank");
                                            } else if (Pokemon.this.specie.name.equals("miltank")) {
                                                sameBaseSpecie = sameBaseSpecie || pokemon7.baseSpecie().equals("tauros");
                                            } else if (Pokemon.this.baseSpecie().equals("nidoran_f")) {
                                                sameBaseSpecie = sameBaseSpecie || pokemon7.baseSpecie().equals("nididoran_m");
                                            } else if (Pokemon.this.baseSpecie().equals("nidoran_m")) {
                                                sameBaseSpecie = sameBaseSpecie || pokemon7.baseSpecie().equals("nididoran_f");
                                            }
                                            if (sameBaseSpecie && pokemon7.mapTiles == Pokemon.this.mapTiles) {
                                                if (Math.abs(Pokemon.this.position.x - pokemon7.position.x) < Math.abs(Pokemon.this.position.y - pokemon7.position.y)) {
                                                    if (pokemon7.position.y < Pokemon.this.position.y) {
                                                        nearbyDir = "down";
                                                    } else {
                                                        nearbyDir = "up";
                                                    }
                                                } else if (pokemon7.position.x < Pokemon.this.position.x) {
                                                    nearbyDir = "left";
                                                } else {
                                                    nearbyDir = "right";
                                                }
                                                this.nearbyDir2 = nearbyDir;
                                                if (this.nearbyDir == null) {
                                                    this.nearbyDir = nearbyDir;
                                                }
                                            }
                                        }
                                    }
                                    this.moveTimer = game.map.rand.nextInt(180) + 60;
                                }
                                String[] dirs = {"up", "down", "left", "right"};
                                Pokemon.this.dirFacing = dirs[game.map.rand.nextInt(dirs.length)];
                                if (this.nearbyDir != null && Game.rand.nextInt(100) < 30) {
                                    if (this.nearbyDir2 == null || Game.rand.nextInt(100) >= 50) {
                                        Pokemon.this.dirFacing = this.nearbyDir;
                                    } else {
                                        Pokemon.this.dirFacing = this.nearbyDir2;
                                    }
                                }
                                Vector2 newPos = Pokemon.this.facingPos(this.pos1);
                                Tile temp = Pokemon.this.mapTiles.get(newPos);
                                boolean collidesWithPlayer = false;
                                Iterator<Player> it = game.players.values().iterator();
                                while (true) {
                                    if (it.hasNext()) {
                                        if (newPos.equals(it.next().position)) {
                                            collidesWithPlayer = true;
                                            break;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                if (temp != null) {
                                    Tile currTile2 = Pokemon.this.mapTiles.get(Pokemon.this.position);
                                    if (Pokemon.this.inWater) {
                                        boolean foundShore = false;
                                        int i2 = 0;
                                        while (true) {
                                            if (i2 >= Pokemon.POSITIONS.length) {
                                                break;
                                            }
                                            Tile tile2 = Pokemon.this.mapTiles.get(this.pos2.set(Pokemon.this.position).add(Pokemon.POSITIONS[i2]));
                                            if (!(tile2 == null || tile2.name.contains("water"))) {
                                                foundShore = true;
                                                break;
                                            }
                                            i2++;
                                        }
                                        if (foundShore) {
                                            boolean foundShore2 = false;
                                            int i3 = 0;
                                            while (true) {
                                                if (i3 >= Pokemon.POSITIONS.length) {
                                                    break;
                                                }
                                                Tile tile3 = Pokemon.this.mapTiles.get(this.pos2.set(newPos).add(Pokemon.POSITIONS[i3]));
                                                if (!(tile3 == null || tile3.name.contains("water"))) {
                                                    foundShore2 = true;
                                                    break;
                                                }
                                                i3++;
                                            }
                                            if (!foundShore2 || !temp.name.contains("water") || game.map.pokemon.containsKey(newPos)) {
                                                return;
                                            }
                                        }
                                    }
                                    if (!Pokemon.this.inWater) {
                                        isSolid = temp == null || temp.isSolid;
                                    } else if (Pokemon.onlySwim.contains(Pokemon.this.specie.name)) {
                                        isSolid = temp == null || !temp.isWater;
                                    } else {
                                        isSolid = temp != null && !temp.isWater && temp.isSolid;
                                    }
                                    boolean isLedge2 = temp.isLedge || (currTile2 != null && currTile2.isLedge && currTile2.ledgeDir().equals("up") && Pokemon.this.dirFacing.equals("up"));
                                    if (!isSolid && !isLedge2 && !temp.name.contains("door") && !temp.nameUpper.contains("gate") && !temp.nameUpper.contains("door") && !game.map.pokemon.containsKey(newPos) && !game.player.position.equals(newPos) && !collidesWithPlayer) {
                                        game.actionStack.remove(this);
                                        Pokemon pokemon8 = Pokemon.this;
                                        Objects.requireNonNull(pokemon8);
                                        Action action2 = new Moving(pokemon8, 2, 1.0f, true, null);
                                        action2.append(this);
                                        game.insertAction(action2);
                                        Pokemon.this.standingAction = action2;
                                    } else {
                                        return;
                                    }
                                } else {
                                    return;
                                }
                            } else {
                                if (!Pokemon.this.dirFacing.equals("up") || Pokemon.this.position.y % 64.0f != 0.0f) {
                                    if (!Pokemon.this.dirFacing.equals("left") || Pokemon.this.position.x % 64.0f != 0.0f) {
                                        if (!Pokemon.this.dirFacing.equals("down") || Pokemon.this.position.y % 64.0f != 0.0f) {
                                            if (Pokemon.this.dirFacing.equals("right") && Pokemon.this.position.x % 64.0f == 0.0f) {
                                                if (Pokemon.this.position.y % 128.0f == 64.0f) {
                                                    Pokemon.this.dirFacing = "down";
                                                } else {
                                                    Pokemon.this.dirFacing = "up";
                                                }
                                            }
                                        } else if (Pokemon.this.position.x % 128.0f == 0.0f) {
                                            Pokemon.this.dirFacing = "left";
                                        } else {
                                            Pokemon.this.dirFacing = "right";
                                        }
                                    } else if (Pokemon.this.position.y % 128.0f == 64.0f) {
                                        Pokemon.this.dirFacing = "down";
                                    } else {
                                        Pokemon.this.dirFacing = "up";
                                    }
                                } else if (Pokemon.this.position.x % 128.0f == 0.0f) {
                                    Pokemon.this.dirFacing = "left";
                                } else {
                                    Pokemon.this.dirFacing = "right";
                                }
                                Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
                                Vector2 newPos2 = Pokemon.this.facingPos(this.pos1);
                                Tile temp2 = Pokemon.this.mapTiles.get(newPos2);
                                boolean collidesWithPlayer2 = false;
                                Iterator<Player> it2 = game.players.values().iterator();
                                while (true) {
                                    if (it2.hasNext()) {
                                        if (newPos2.equals(it2.next().position)) {
                                            collidesWithPlayer2 = true;
                                            break;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                                Tile currTile3 = Pokemon.this.mapTiles.get(Pokemon.this.position);
                                boolean isLedge3 = (temp2 != null && temp2.isLedge) || (currTile3 != null && currTile3.isLedge && currTile3.ledgeDir().equals("up") && Pokemon.this.dirFacing.equals("up"));
                                if (temp2 != null && !temp2.isSolid && !isLedge3 && !temp2.name.contains("door") && !temp2.nameUpper.contains("gate") && !temp2.nameUpper.contains("door") && !game.map.pokemon.containsKey(newPos2) && !game.player.position.equals(newPos2) && !collidesWithPlayer2) {
                                    game.actionStack.remove(this);
                                    Pokemon pokemon9 = Pokemon.this;
                                    Objects.requireNonNull(pokemon9);
                                    Action action3 = new Moving(pokemon9, 2, 1.0f, true, null);
                                    action3.append(this);
                                    game.insertAction(action3);
                                    Pokemon.this.standingAction = action3;
                                    return;
                                } else if (Pokemon.this.dirFacing.equals("up")) {
                                    Pokemon.this.dirFacing = "down";
                                    return;
                                } else if (Pokemon.this.dirFacing.equals("left")) {
                                    Pokemon.this.dirFacing = "right";
                                    return;
                                } else if (Pokemon.this.dirFacing.equals("down")) {
                                    Pokemon.this.dirFacing = "up";
                                    return;
                                } else if (Pokemon.this.dirFacing.equals("right")) {
                                    Pokemon.this.dirFacing = "left";
                                    return;
                                } else {
                                    return;
                                }
                            }
                        }
                        this.moveTimer--;
                    } else {
                        Pokemon.this.friendTimer = Pokemon.friendTimerMax;
                        ArrayList<Vector2> checkThese = new ArrayList<>();
                        HashMap<Vector2, Vector2> prevTiles = new HashMap<>();
                        Vector2 pos = this.pos1.set(Pokemon.this.position);
                        checkThese.add(pos);
                        prevTiles.put(pos, null);
                        Pokemon foundPokemon = null;
                        for (int tries = 0; tries < 20 && !checkThese.isEmpty(); tries++) {
                            pos = checkThese.remove(0);
                            foundPokemon = game.map.pokemon.get(pos);
                            if (foundPokemon != null) {
                                if (foundPokemon == Pokemon.this.friend) {
                                    break;
                                } else if (foundPokemon != Pokemon.this) {
                                }
                            }
                            for (int i4 = 0; i4 < Pokemon.FRIEND_OFFSETS.length; i4++) {
                                Vector2 newPos3 = this.pos2.set(pos).add(Pokemon.FRIEND_OFFSETS[i4]);
                                Tile temp3 = Pokemon.this.mapTiles.get(newPos3);
                                if (temp3 != null && !temp3.isSolid && !temp3.isLedge && !temp3.name.contains("door") && !temp3.nameUpper.contains("gate") && !temp3.nameUpper.contains("door") && !game.player.position.equals(newPos3) && !prevTiles.containsKey(newPos3)) {
                                    checkThese.add(newPos3.cpy());
                                    prevTiles.put(newPos3.cpy(), pos.cpy());
                                }
                            }
                        }
                        if (foundPokemon == Pokemon.this.friend) {
                            foundPokemon.moveDirs.clear();
                            foundPokemon.numMoves.clear();
                            while (prevTiles.get(pos) != null) {
                                Vector2 prevPos = prevTiles.get(pos);
                                String direction = null;
                                if (prevPos.x < pos.x) {
                                    direction = "left";
                                } else if (prevPos.x > pos.x) {
                                    direction = "right";
                                } else if (prevPos.y < pos.y) {
                                    direction = "down";
                                } else if (prevPos.y > pos.y) {
                                    direction = "up";
                                }
                                if (direction != null) {
                                    foundPokemon.moveDirs.add(direction);
                                    foundPokemon.numMoves.add(Float.valueOf(1.2f));
                                    pos = prevPos;
                                } else {
                                    return;
                                }
                            }
                            checkThese.clear();
                            prevTiles.clear();
                            pos.set(Pokemon.this.position);
                            checkThese.add(pos);
                            prevTiles.put(pos, null);
                            int tries2 = 0;
                            while (tries2 < 30 && !checkThese.isEmpty()) {
                                pos = checkThese.remove(0);
                                for (Vector2 offset : Pokemon.FRIEND_OFFSETS) {
                                    Vector2 newPos4 = this.pos2.set(pos).add(offset);
                                    Tile temp4 = Pokemon.this.mapTiles.get(newPos4);
                                    if (temp4 != null && !temp4.isSolid && !temp4.isLedge && !temp4.name.contains("door") && !temp4.nameUpper.contains("gate") && !temp4.nameUpper.contains("door") && !game.map.pokemon.containsKey(newPos4) && !game.player.position.equals(newPos4) && !prevTiles.containsKey(newPos4)) {
                                        checkThese.add(newPos4.cpy());
                                        prevTiles.put(newPos4.cpy(), pos.cpy());
                                    }
                                }
                                tries2++;
                            }
                            Pokemon.this.moveDirs.clear();
                            Pokemon.this.numMoves.clear();
                            while (tries2 >= 20 && prevTiles.get(pos) != null) {
                                Vector2 prevPos2 = prevTiles.get(pos);
                                String direction2 = null;
                                if (prevPos2.x < pos.x) {
                                    direction2 = "right";
                                } else if (prevPos2.x > pos.x) {
                                    direction2 = "left";
                                } else if (prevPos2.y < pos.y) {
                                    direction2 = "up";
                                } else if (prevPos2.y > pos.y) {
                                    direction2 = "down";
                                }
                                if (direction2 != null) {
                                    Pokemon.this.moveDirs.add(direction2);
                                    Pokemon.this.numMoves.add(Float.valueOf(1.2f));
                                    pos = prevPos2;
                                } else {
                                    return;
                                }
                            }
                            if (Pokemon.this.position.dst2(game.player.position) < 16384.0f && game.battle.drawAction == null && game.playerCanMove && game.map.tiles == Pokemon.this.mapTiles) {
                                game.insertAction(new PlayMusic(Pokemon.this, true, (Action) null));
                            }
                            Pokemon pokemon10 = Pokemon.this;
                            Objects.requireNonNull(pokemon10);
                            game.insertAction(new Emote("happy", null));
                            Pokemon pokemon11 = Pokemon.this.friend;
                            Objects.requireNonNull(pokemon11);
                            game.insertAction(new Emote("happy", null));
                        }
                    }
                }
            } else if (!Pokemon.this.mapTiles.containsKey(Pokemon.this.position) || !Pokemon.this.mapTiles.get(Pokemon.this.position).isGrass) {
                ArrayList<String> preferMoves = new ArrayList<>();
                String moveDir = null;
                Vector2 tl = this.pos1;
                tl.set(Pokemon.this.position).add(-96.0f, -96.0f);
                while (true) {
                    if (tl.y >= Pokemon.this.position.y + 96.0f) {
                        break;
                    }
                    if (tl.x > Pokemon.this.position.x + 96.0f) {
                        tl.x = Pokemon.this.position.x - 112.0f;
                        tl.y += 16.0f;
                    } else {
                        Tile tile4 = Pokemon.this.mapTiles.get(tl);
                        if (tile4 != null && tile4.isGrass && game.map.rand.nextInt(5) == 0) {
                            if (Pokemon.this.position.x - tile4.position.x < Pokemon.this.position.y - tile4.position.y) {
                                if (tile4.position.y < Pokemon.this.position.y) {
                                    preferMoves.add("down");
                                } else {
                                    preferMoves.add("right");
                                }
                            } else if (tile4.position.x < Pokemon.this.position.x) {
                                preferMoves.add("left");
                            } else {
                                preferMoves.add("up");
                            }
                        }
                    }
                    tl.x += 16.0f;
                }
                if (Pokemon.this.position.x - game.player.position.x < Pokemon.this.position.y - game.player.position.y) {
                    Vector2 up = this.pos1.set(Pokemon.this.position.x, Pokemon.this.position.y + 16.0f);
                    Vector2 left = this.pos2.set(Pokemon.this.position.x - 16.0f, Pokemon.this.position.y);
                    Pokemon.this.mapTiles.get(up);
                    Tile leftTile = Pokemon.this.mapTiles.get(left);
                    if (game.player.position.y < Pokemon.this.position.y) {
                        preferMoves.add("up");
                    } else if (!leftTile.isSolid) {
                        preferMoves.add("left");
                    }
                }
                Vector2 right = this.pos1.set(Pokemon.this.position.x + 16.0f, Pokemon.this.position.y);
                Vector2 down = this.pos2.set(Pokemon.this.position.x, Pokemon.this.position.y - 16.0f);
                Tile rightTile = Pokemon.this.mapTiles.get(right);
                Tile downTile = Pokemon.this.mapTiles.get(down);
                if (game.player.position.x < Pokemon.this.position.x) {
                    preferMoves.add("right");
                } else {
                    preferMoves.add("down");
                }
                Tile upTile = Pokemon.this.mapTiles.get(this.pos1.set(Pokemon.this.position.x, Pokemon.this.position.y + 16.0f));
                Tile leftTile2 = Pokemon.this.mapTiles.get(this.pos2.set(Pokemon.this.position.x - 16.0f, Pokemon.this.position.y));
                if (game.player.position.y < Pokemon.this.position.y) {
                    preferMoves.add("up");
                } else {
                    preferMoves.add("left");
                }
                Iterator<String> it3 = preferMoves.iterator();
                while (true) {
                    if (!it3.hasNext()) {
                        break;
                    }
                    String move2 = it3.next();
                    if (!move2.equals("up") || upTile.isSolid || upTile.isLedge || upTile.nameUpper.contains("gate") || upTile.name.contains("door")) {
                        if (!move2.equals("right") || rightTile.isSolid || rightTile.isLedge || rightTile.nameUpper.contains("gate") || rightTile.name.contains("door")) {
                            if (move2.equals("down") && !downTile.isSolid && !downTile.isLedge && !downTile.nameUpper.contains("gate") && !downTile.name.contains("door")) {
                                moveDir = move2;
                                break;
                            }
                            if (!(!move2.equals("left") || leftTile2.isSolid || leftTile2.isLedge || leftTile2.nameUpper.contains("gate") || leftTile2.name.contains("door"))) {
                                moveDir = move2;
                                break;
                            }
                        } else {
                            moveDir = move2;
                            break;
                        }
                    } else {
                        moveDir = move2;
                        break;
                    }
                }
                if (moveDir != null) {
                    Pokemon.this.dirFacing = moveDir;
                    game.actionStack.remove(this);
                    Pokemon pokemon12 = Pokemon.this;
                    Objects.requireNonNull(pokemon12);
                    Action action4 = new Moving(pokemon12, 1, 2.0f, this.alternate, this);
                    this.alternate = !this.alternate;
                    game.insertAction(action4);
                    Pokemon.this.standingAction = action4;
                }
            } else {
                Pokemon.this.isRunning = false;
                game.map.pokemon.remove(Pokemon.this.position);
                Pokemon.this.removeDrawActions(game);
            }
        }

        public void remoteStep(Game game) {
            Pokemon.this.currOwSprite = Pokemon.this.standingSprites.get(Pokemon.this.dirFacing);
            if (Pokemon.this.shouldMove) {
                Pokemon.this.shouldMove = false;
                game.actionStack.remove(this);
                Pokemon pokemon = Pokemon.this;
                Objects.requireNonNull(pokemon);
                Action action = new Moving(pokemon, 2, 1.0f, true, null);
                action.append(this);
                game.insertAction(action);
                Pokemon.this.standingAction = action;
            }
        }

        @Override // com.corona.game.Action
        public void step(Game game) {
            if (Pokemon.this.type == Player.Type.LOCAL) {
                localStep(game);
            } else {
                remoteStep(game);
            }
        }
    }
}
